Skip to content

Instantly share code, notes, and snippets.

@BnayaZil
Created May 15, 2018 12:39
Show Gist options
  • Save BnayaZil/111ad63752e0a1bfde827673de742839 to your computer and use it in GitHub Desktop.
Save BnayaZil/111ad63752e0a1bfde827673de742839 to your computer and use it in GitHub Desktop.
// factoryA.js
import FactoryB from './factoryB'
export default class FactoryA {
constructor(data) {
// ...
}
doStuffWithB(data, B = FactoryB) {
const b = new B()
return b.foo(data)
}
}
// factoryA.test.js
describe('FactoryA', () => {
it('doStuffWithB', () => {
const mockData = ['foo']
const a = new FactoryA()
const foo = jest.fn(() => 'test')
const MockFactoryB = jest.fn(() => ({foo}))
expect(a.doStuffWithB(mockData, MockFactoryB)).toBe('test')
expect(foo).toBeCalledWith(mockData)
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment