Skip to content

Instantly share code, notes, and snippets.

@will-wow
Created May 21, 2019 17:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save will-wow/b33e8aa461ea481858b4da5109f53979 to your computer and use it in GitHub Desktop.
Save will-wow/b33e8aa461ea481858b4da5109f53979 to your computer and use it in GitHub Desktop.
VSCode Snippets for a React/Redux/Jest/Enzyme Project
{
"jest-component": {
"prefix": "jestcomponent",
"body": [
"import React from 'react';",
"import { shallow } from 'enzyme';",
"import $1 from '../$1';",
"",
"describe('$1', () => {",
" let props;",
" let wrapper;",
"",
" beforeEach(() => {",
" props = {};",
" wrapper = shallow(<$1 {...props} />);",
" });",
"",
" it('renders', () => {",
" expect(wrapper.find('')).toHaveLength(1);",
" });",
"",
" describe('', () => {",
" it('', () => {",
" });",
" });",
"});"
]
},
"jest-javascript-file": {
"prefix": "jestjs",
"body": [
"import {$2} from '../$1';",
"",
"describe('$1', () => {",
" describe('$2', () => {",
" it('', () => {",
" expect($2)",
" });",
" });",
"});"
]
},
"react-component": {
"prefix": "reactcomponent",
"body": [
"import React from 'react';",
"import PropTypes from 'prop-types';",
"",
"const $1 = ({}) => {",
" return <div data-id=\"\">content</div>;",
"};",
"",
"$1.propTypes = {",
" className: PropTypes.string,",
"};",
"",
"$1.defaultProps = {",
" className: '',",
"};",
"",
"export default $1;",
""
]
},
"redux-component": {
"prefix": "reduxcomponent",
"body": [
"import React from 'react';",
"import PropTypes from 'prop-types';",
"import { connect } from 'react-redux';",
"import { bindActionCreators } from 'redux';",
"",
"const $1 = ({}) => {",
" return <div data-id=\"\">content</div>;",
"};",
"",
"$1.propTypes = {",
" className: PropTypes.string,",
"};",
"",
"$1.defaultProps = {",
" className: '',",
"};",
"",
"const mapStateToProps = state => {",
" return {};",
"};",
"",
"const mapDispatchToProps = dispatch => bindActionCreators({}, dispatch);",
"",
"export { $1 };",
"",
"export default connect(",
" mapStateToProps,",
" mapDispatchToProps,",
")($1);",
""
]
},
"object-model": {
"prefix": "modelobject",
"body": [
"import PropTypes from 'prop-types';",
"import { camelizeKeys, decamelizeKeys } from 'humps';",
"",
"export const $1Type = PropTypes.shape({",
" id: PropTypes.string,",
"});",
"",
"export const $1ListType = PropTypes.arrayOf($1Type);",
"",
"export const $1FromApi = json => {",
" return camelizeKeys(json);",
"};",
"",
"export const $1ToApi = $1 => {",
" return decamelizeKeys($1, { separator: '-' });",
"};",
""
]
},
"reducer": {
"prefix": "reducer",
"body": [
"import { actionTypes } from '../actions/$1';",
"import { $1 as defaultState } from './default.json';",
"",
"const handlers = {",
" [actionTypes.$2]: state => ({",
" ...state,",
" }),",
"};",
"",
"export default (state = defaultState, action) => {",
" const handler = handlers[action.type];",
" return handler ? handler(state, action) : state;",
"};"
]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment