Created
May 15, 2018 12:39
-
-
Save BnayaZil/111ad63752e0a1bfde827673de742839 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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