javascript - How to mock dependencies for unit tests with ES6 Modules -
i'm trying fiddle ecmascript 6 modules using webpack + traceur transpile es5 commonjs, i'm having trouble unit testing them.
i tried using jest + traceur preprocessor, automocking , dependency names seem screwy, plus can't seem sourcemaps work jest , node-inspector debugging.
is there better framework unit test es6 modules?
i've started employing import * obj
style within tests, imports exports module properties of object can mocked. find lot cleaner using rewire or proxyquire or similar technique.
i can't speak traceur framework used in question, i've found work setup of karma, jasmine, , babel, , i'm posting here seems popular question of type.
i've used strategy when needing mock redux actions. here's short example:
import * exports 'module-you-want-to-mock'; import systemundertest 'module-that-uses-above-module'; describe('your module', () => { beforeeach(() => { spyon(exports, 'somenamedexport'); // mock named export spyon(exports, 'default'); // mock default export }); // ... above functions mocked });
Comments
Post a Comment