509 links
My Links
Home
Login
RSS Feed
ATOM Feed
Tag cloud
Picture wall
Daily
Links per page:
20
50
100
page 1 / 1
Advanced React Component Mocks with Jest and React Testing Library | by Eric Cobb | Medium
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');
});
August 19, 2021 at 5:07:11 PM UTC
- permalink
-
-
https://ericdcobb.medium.com/advanced-react-component-mocks-with-jest-and-react-testing-library-f1ae8838400b
react
tdd
test
Links per page:
20
50
100
page 1 / 1