モジュールで使用すると Jest が動作しないという奇妙な問題が発生しexport default
ています。
問題を再現するためのサンプル リポジトリを作成しました: https://github.com/syropian/jest-test
このモジュールを考えると、その要点は次のとおりです。
const a = {
greet () {
return 'Hello World'
}
}
const b = {
foo () {
return 'bar'
}
}
export default {
a,
b
}
これは機能します:
import myModule from '../src'
describe('My module', () => {
it('works if I import the whole module', () => {
const greeting = myModule.a.greet()
const foo = myModule.b.foo()
expect(greeting).toBe('Hello World')
expect(foo).toBe('bar')
})
})
しかし、これは結果として次のようになりa
ます。b
undefined
import { a, b } from '../src'
describe('My module', () => {
it('works if I import individual exports', () => {
const greeting = a.greet()
const foo = b.foo()
expect(greeting).toBe('Hello World')
expect(foo).toBe('bar')
})
})
.babelrc
セットアップなどについては、提供されたリポジトリを参照してください。
ノードの使用7.3.0