I've been reading about this in the official documentation, in this blogpost, and this issue in jest repo. Neither the documentation or the blogpost cover the scenario I'm trying to test. The issue thread does cover it, but I can't get the tests to pass using any of the solutions proposed there.
Can you complete the following code to make the tests pass?
// a.js
export const foo = () => 'foo-' + bar()
export const bar = () => 'bar'
// a.test.js
import {
foo,
bar
} from './a'
describe('foo', () => {
it('should return foo-MOCKED_BAR', () => {
expect(foo()).toBe('foo-MOCKED_BAR')
})
it('should have the mocked implementation of bar', () => {
expect(bar()).toBe('MOCKED_BAR')
})
})
describe('bar', () => {
it('should have the original implementation of bar', () => {
expect(bar()).toBe('bar')
})
})
describe('foo and bar together', () => {
it('should have the original implementation of both', () => {
expect(foo()).toBe('foo-bar')
})
})
Thanks!
Aucun commentaire:
Enregistrer un commentaire