https://github.com/59naga/babel-plugin-add-module-exports
avoids need for:
require('./bundle.js') // { default: 'foo' }
require('./bundle.js').default // 'foo'
so our OG code still works fine:
require('./bundle.js') // foo
Convert to export default
https://www.npmjs.com/package/babel-plugin-rewire
- No more explicit "rewire()" calls, auto translated via .babelrc
- Calls to
__get__
are now__GetDependency__
- Must reset dependency if you
__set__
it, since we no longer manuallyrewire
in abeforeEach
block - Assertions like
expect(server)to.have.keys('function1', 'function2'...)
should now useinclude
instead ofhave
, since the module will have extra rewired methods
Utils.__set__('_findFoo', _findFooSpy)
// ... some expect(...) assertion
Utils.__ResetDependency__('_findFoo')
- Removed node module from repo, but all tests using proxyquire are currently skipped (
describe.skip
) - In a followup we should transition these to use the
getDependencies
approach
If you see this error, make sure you're exporting the function under test as a named export in the file under test
Is there a __set__
call in a preceding test? Make sure you're calling __ResetDependency__
any time you do this, otherwise downstream tests will still respect whatever mock you passed to the module in your __set__
call
With this you'll see:
AssertionError: expected { Object (get, GetDependency, ...) } to be a function
Because of how babel-rewire works, each module under test gets several other methods (__GetDependency
, etc). Proposed solution: don't typeof
test actions anymore (?)