Skip to content

Instantly share code, notes, and snippets.

@AviKKi
Last active October 2, 2021 13:09
Show Gist options
  • Save AviKKi/6ad27a8ffdc4d79ff0d130e548552b69 to your computer and use it in GitHub Desktop.
Save AviKKi/6ad27a8ffdc4d79ff0d130e548552b69 to your computer and use it in GitHub Desktop.
TS test notes
## Initialize
npx create-react-app . --template typescript
npm install @mui/material @emotion/react @emotion/styled
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'))
### 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