Created
June 10, 2021 18:36
-
-
Save VitorLuizC/034ab2c5c205e5d1a4e355e87ef0ea97 to your computer and use it in GitHub Desktop.
This file contains 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 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(); | |
}); | |
}); | |
This file contains 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 { 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