Skip to content

Instantly share code, notes, and snippets.

@ChrisLowe-Takor
Created December 7, 2020 09:01
Show Gist options
  • Save ChrisLowe-Takor/1b5f9a902ca72ba5f614a9cd6dc530a4 to your computer and use it in GitHub Desktop.
Save ChrisLowe-Takor/1b5f9a902ca72ba5f614a9cd6dc530a4 to your computer and use it in GitHub Desktop.
React test snippet
"React test": {
"prefix": "rtest",
"body": [
"import * as React from 'react';",
"import { createStore } from 'redux';",
"import { render, screen } from '@testing-library/react';",
"import '@testing-library/jest-dom/extend-expect';",
"",
"import { Provider } from 'react-redux';",
"import { state } from '../../../../store/root-reducer';",
"",
"import $1 from './${TM_FILENAME/\\.test\\.tsx$|/${1}${2}/g}';",
"",
"//",
"// yarn test ${TM_DIRECTORY/.*(?=src)/$1/}/${TM_FILENAME} --coverage --collectCoverageOnlyFrom=${TM_DIRECTORY/.*(?=src)/$1/}/${TM_FILENAME/\\.test\\.tsx$|/${1}${2}/g}.tsx",
"//",
"describe('$1 Component', () => {",
"",
" it('Mounts the component', () => {",
" const store = createStore(state);",
" render(",
" <Provider store={store}>",
" <$1 />",
" </Provider>",
" );",
"",
" console.log(screen.logTestingPlaygroundURL());",
" //expect(screen.queryByRole('heading', { name: /my title/i })).toBeInTheDocument();",
" });",
"});"
],
"description": "React test"
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment