Created
April 11, 2018 06:33
-
-
Save jussikinnula/4a303e390794800858ef740f4887b90d to your computer and use it in GitHub Desktop.
Jest
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
const fooFn = jest.fn().mockImplementation(() => Promise.resolve('bar')); | |
const barFn = jest.fn(); | |
jest.mock('./foo', () => ({ foo: fooFn, bar: barFn }); | |
import Foo from './foo'; | |
describe('foo module tests', () => { | |
it('runs foo', () => { | |
const foo = Foo(); | |
expect(fooFn).toHaveBeenCalled(); | |
expect(barFn).toHaveBeenCalledTimes(0); | |
}); | |
}); |
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
class Foo { | |
constructor() { | |
console.log('new Foo created'); | |
this.foo(); | |
} | |
foo() { | |
console.log('Foo's foo method called'); | |
} | |
bar() { | |
console.log('Foo's bar method called'); | |
} | |
} | |
export default Foo; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment