Skip to content

Instantly share code, notes, and snippets.

@ericdcobb
Created February 13, 2020 00:17
Show Gist options
  • Save ericdcobb/93ca063ffd177ee955e4f85f21c023ce to your computer and use it in GitHub Desktop.
Save ericdcobb/93ca063ffd177ee955e4f85f21c023ce to your computer and use it in GitHub Desktop.
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