jeudi 22 juin 2017

Jest: Can't use default exports?

I'm having a weird issue where Jest does not seem to work when using export default on a module.

I've created a sample repo to reproduce the issue: http://ift.tt/2rG8e35

The gist of it is, given this module:

const a = {
  greet () {
    return 'Hello World'
  }
}

const b = {
  foo () {
    return 'bar'
  }
}

export default {
  a,
  b
}    

This works:

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')
  })
})

but this results in a and b being 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')
  })
})

See the provided repo for .babelrc setup, etc.

Using node 7.3.0

Aucun commentaire:

Enregistrer un commentaire