Skip to content

Instantly share code, notes, and snippets.

@VitorLuizC
Created June 10, 2021 18:36
Show Gist options
  • Save VitorLuizC/034ab2c5c205e5d1a4e355e87ef0ea97 to your computer and use it in GitHub Desktop.
Save VitorLuizC/034ab2c5c205e5d1a4e355e87ef0ea97 to your computer and use it in GitHub Desktop.
import mockNanoId from '__mocks__/mockNanoId';
import { render } from '@testing-library/react';
import Home from './Home';
describe('Home | component | integration test', () => {
beforeEach(mockNanoId);
it('renders the home page', () => {
const { container } = render(<Home />);
expect(container.firstChild).toMatchSnapshot();
});
});
import { nanoid } from 'nanoid';
jest.mock('nanoid', () => ({
nanoid: jest.fn(() => '0'),
}));
function mockNanoId() {
let count = 0;
/** @type {jest.Mock} */
(nanoid).mockReset().mockImplementation(() => {
count += 1;
return count.toString(10);
});
}
export default mockNanoId;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment