Created
February 13, 2020 00:17
-
-
Save ericdcobb/93ca063ffd177ee955e4f85f21c023ce to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import React from 'react'; | |
import { render } from '@testing-library/react'; | |
import App from './App'; | |
import MyComponent from './MyComponent'; | |
const MockMyComponent = () => { | |
React.useEffect(() => { | |
console.log('using an effect'); | |
}); | |
return (<div>Hello World</div>); | |
}; | |
jest.mock('./MyComponent', () => ({ | |
__esModule: true, | |
namedExport: jest.fn(), | |
default: jest.fn() | |
})); | |
beforeAll(() => { | |
MyComponent.mockImplementation(MockMyComponent); | |
}); | |
test('renders', () => { | |
const { container } = render(<App/>); | |
expect(container.textContent) | |
.toMatch('Hello World'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment