jasmine - Reset an ES6 module with SystemJS (for unit tests)? -
our workflow includes using es6 modules. includes unit tests. import
modules under test. problem original authors decided have every module return objects, , have global singletons (because of how es6 imports work) throughout code base---a classic unit testing problem.
is there way "reset" said modules systemjs after each test?
sample unit test (loaded karma-systemjs):
import mut './mut' // module under test describe('mut', () => { it('should stuff', () => { mut.value = 'foo' }) it('should more stuff', () => { // value should not 'foo' here. how reset mut? })
check out this issue on github, , particularly this comment.
try deleting , re-importing module in beforeeach
block so:
describe('mut', () => { let mut; beforeeach((done) => { // remove previous version system.delete(system.normalizesync('./mut')) // re-import module system.import('./mut').then((imported) => { mut = imported }).then(done, fail) }) it('should stuff, () => { mut.value = 'foo' expect(mut.value).tobe('foo') }) it('should more stuff', () => { expect(mut.value).not.tobe('foo') }) })
Comments
Post a Comment