Skip to content

Instantly share code, notes, and snippets.

@laurazenc
Last active September 8, 2021 14:15
Show Gist options
  • Save laurazenc/c7a1ce70df729985a113ed9db8089ba7 to your computer and use it in GitHub Desktop.
Save laurazenc/c7a1ce70df729985a113ed9db8089ba7 to your computer and use it in GitHub Desktop.
VSCode snippets
{
"Jest suite test for components": {
"prefix": "test-suite-comp",
"body": [
"import { render, screen } from '@testing-library/react'",
"import { ${TM_FILENAME_BASE/([^.]+).*/${1}/} } from './${TM_FILENAME_BASE/([^.]+).*/${1}/}'",
"",
"describe('${TM_FILENAME_BASE/([^.]+).*/${1}/}', () => {",
" it('should render', () => {",
" const renderInstance = render(<${TM_FILENAME_BASE/([^.]+).*/${1}/}/>)",
" expect(renderInstance.asFragment().firstChild).toBeTruthy()",
" })",
"})"
],
"description": "Jest file structure for react component"
},
"Jest suite test": {
"prefix": "test-suite",
"body": [
"import { ${TM_FILENAME_BASE/([^.]+).*/${1}/} } from './${TM_FILENAME_BASE/([^.]+).*/${1}/}'",
"",
"describe('${TM_FILENAME_BASE/([^.]+).*/${1}/}', () => {",
" it('should do something', () => {",
" expect(true).toBeTruthy()",
" })",
"})"
],
"description": "Jest file structure"
}
}
{
"Create story": {
"prefix": "story",
"body": [
"import { Meta, Story } from '@storybook/react'",
"import { ${TM_FILENAME_BASE/([^.]+).*/${1}/} } from './${TM_FILENAME_BASE/([^.]+).*/${1}/}'",
"",
"export default {",
" title: '${2}/${TM_FILENAME_BASE/([^.]+).*/${1}/}',",
" component: ${TM_FILENAME_BASE/([^.]+).*/${1}/},",
" parameters: {",
" controls: {",
" sort: 'alpha',",
" exclude: ['spTheme'],",
" },",
" docs: { source: { excludeDecorators: true } },",
" design: {",
" url: 'design url here',",
" },",
"},",
"} as Meta",
"",
"const Template: Story = (props: ${TM_FILENAME_BASE/([^.]+).*/${1}/}Props) => <${TM_FILENAME_BASE/([^.]+).*/${1}/} {...props}></${TM_FILENAME_BASE/([^.]+).*/${1}/}>",
"",
"export const Default = Template.bind({})",
"Default.args = {}"
],
"description": "Storybook file structure"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment