Last active
October 2, 2021 13:09
-
-
Save AviKKi/6ad27a8ffdc4d79ff0d130e548552b69 to your computer and use it in GitHub Desktop.
TS test notes
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
## Initialize | |
npx create-react-app . --template typescript | |
npm install @mui/material @emotion/react @emotion/styled |
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
function mockFetch(url: string) { | |
if (url.indexOf('countries/positions') !== -1) | |
return { | |
ok: true, | |
status: 200, | |
json: async () => ({ "error": false, "msg": "country and capitals retrieved", "data": { "name": "India", "capital": "New Delhi" } }) | |
} | |
} | |
beforeEach(() => (window.fetch = jest.fn().mockImplementation(mockFetch))) | |
beforeAll(() => jest.spyOn(window, 'fetch')) |
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
### Links | |
https://dev.to/mbellagamba/testing-library-recipes-choosing-query-279p | |
https://github.com/psongpin/react-testing-recipes |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment