-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathsnippets.json
431 lines (431 loc) · 11.7 KB
/
snippets.json
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
{
/*
// Place your snippets for JavaScript here. Each snippet is defined under a snippet name and has a prefix, body and
// description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the
// same ids are connected.
// Example:
"Print to console": {
"prefix": "log",
"body": [
"console.log('$1');",
"$2"
],
"description": "Log output to console"
}
*/
"Print to console": {
"prefix": "log",
"body": ["console.log('$1');"]
},
"Blank dumb component": {
"prefix": "dumb",
"body": [
"import React from 'react';",
"import PropTypes from 'prop-types';",
"import { View } from 'react-native';",
"$2",
"import styles from './styles';",
"$2",
"const propTypes = {};",
"$2",
"const defaultProps = {};",
"$2",
"const $1 = ({ someProp }) => {",
"return (",
"<View style={styles.container}>",
" <View />",
"</View>",
");",
"}",
"$2",
"$1.propTypes = propTypes;",
"$1.defaultProps = defaultProps;",
"$2",
"export default $1;",
"$2"
]
},
"Blank functional component": {
"prefix": "functional",
"body": [
"import React from 'react';",
"import PropTypes from 'prop-types';",
"import { View } from 'react-native';",
"$2",
"import styles from './styles';",
"$2",
"export default class $1 extends React.Component {",
"constructor(props) {",
"super(props)",
"$2",
"this.state = {};",
"}",
"$2",
" static propTypes = {};",
"$2",
" static defaultProps = {};",
"$2",
" render() {",
" return (",
" <View style={styles.container}>",
" <View />",
" </View>",
" );",
" }",
"}",
"$2"
]
},
"Blank list component": {
"prefix": "list",
"body": [
"import React from 'react';",
"import PropTypes from 'prop-types';",
"import { View, FlatList } from 'react-native';",
"$2",
"import styles from './styles';",
"$2",
"export default class $1 extends React.Component {",
"constructor(props) {",
"super(props)",
"$2",
"this.renderItem = this.renderItem.bind(this)",
"}",
"$2",
" static propTypes = {",
" data: PropTypes.arrayOf(PropTypes.any),",
" };",
"$2",
" static defaultProps = {};",
"$2",
" renderItem ({ item, index }) {",
"return (",
" <View>",
" <View />",
" </View>",
" )};",
"$2",
" render() {",
" return (",
" <FlatList",
" keyExtractor={({ id }) => id}",
" data={this.props.data}",
" renderItem={this.renderItem}",
" style={styles.wrapper}",
" contentContainerStyle={styles.container}",
" />",
" );",
" }",
"}",
"$2"
]
},
"Blank container component": {
"prefix": "container",
"body": [
"import React from 'react';",
"import PropTypes from 'prop-types';",
"import { connect } from 'react-redux';",
"import { View } from 'react-native';",
"$2",
"export class $1 extends React.Component {",
"constructor(props) {",
"super(props)",
"$2",
"this.state = {};",
"}",
"$2",
" static propTypes = {};",
"$2",
" static defaultProps = {};",
"$2",
" render() {",
" return (",
" <View>",
" <View />",
" </View>",
" );",
" }",
"}",
"$2",
"function mapStateToProps(state) {",
" return {};",
"}",
"$2",
"export default connect(mapStateToProps)($1);",
"$2"
]
},
"Blank saga": {
"prefix": "saga",
"body": [
"import { call, put } from 'redux-saga/effects';",
"$4",
"import { $1 } from '../../../services';",
"import { app } from '../../../utils';",
"$4",
"export default function* $2(action) {",
" try {",
" const response = yield call($1.$2, $3);",
" const nextAction = app.prepareNextAction(action, response);",
"$4",
" if (nextAction) {",
" yield put(",
" nextAction",
" );",
" }",
" } catch (error) {",
"$4",
" yield put({",
" type: 'logError',",
" payload: {",
" error: app.createError(error),",
" date: Date.now()",
" }",
" });",
" }",
"}",
"$4"
]
},
"Blank stylesheet": {
"prefix": "styles",
"body": [
"import { StyleSheet } from 'react-native';",
"$1",
"import styleConstants from '../../static/styleConstants';",
"$1",
"const styles = StyleSheet.create({});",
"$1",
"export default styles;"
]
},
"Blank component index": {
"prefix": "index",
"body": ["import $1 from './$1';", "$2", "export default $1;"]
},
"Blank test": {
"prefix": "test",
"body": [
"import React from 'react';",
"import renderer from 'react-test-renderer';",
"$2",
"import $1 from '..';",
"$2",
"describe('$1', () => {",
"const spies = [];",
"const dispatch = jest.fn();",
"$2",
"describe('renders', () => {",
"it('renders with minimum required props', () => {",
"const component = renderer.create(<$1 />);",
"$2",
"expect(component).toMatchSnapshot();",
"});",
"$2",
"});",
"$2",
"describe('methods', () => {",
"});",
"$2",
"describe('lifecycle methods', () => {",
"});",
"$2",
"describe('actions', () => {",
"});",
"$2",
"afterEach(() => {",
"spies.forEach((spy) => {",
"if (spy) {",
"spy.mockClear();",
"}",
"});",
"dispatch.mockClear()",
"});",
"});"
]
},
"Blank functional test": {
"prefix": "testf",
"body": [
"it('renders a $1', () => {",
" const component = renderer.create(<$1 />);",
" const { root } = component;",
" const instance = component.getInstance();",
"});"
]
},
"Blank utility test": {
"prefix": "testu",
"body": [
"import $1 from '..';",
"$5",
"describe('$1()', () => {",
"it('should $2', () => {",
" expect($1($3)).toBe($4);",
"})",
"});"
]
},
"Blank reducer test": {
"prefix": "testr",
"body": [
"import reducer from '..';",
"import initialState from '../initialState';",
"$1",
"it('should return the initial state', () => {",
" expect(reducer(undefined, {})).toEqual(initialState);",
"});"
]
},
"Blank service test": {
"prefix": "testse",
"body": [
"import $1 from '..';",
"$3",
"jest.mock('$2', () => {",
" return {",
" $1: jest.fn(() => {",
" return new Promise((resolve) => {",
" $3",
" });",
" }),",
" };",
"});",
"$3",
"describe('$1', () => {",
" it('resolves a promise', async () => {",
" expect.assertions(1);",
" const response = await $1();",
" expect(response).toEqual();",
" });",
"});"
]
},
"Blank saga test": {
"prefix": "tests",
"body": [
"import { call, put } from 'redux-saga/effects';",
"import sagaHelper from 'redux-saga-testing';",
"${4}",
"import { app } from '../../../../utils';",
"import $1 from '..';",
"${4}",
"const $2 = {",
" $1: jest.fn(),",
"};",
"${4}",
"const action = {",
" type: '$1',",
"};",
"${4}",
"const nextAction = {",
" type: 'SUCCESS',",
"};",
"${4}",
"const actionWithNextAction = { ...action, meta: { ...action.meta, nextAction } };",
"${4}",
"const response = { foo: 'bar' };",
"${4}",
"describe('When testing the saga without a nextAction and without a response from the api', () => {",
" const it = sagaHelper($1(action));",
"${4}",
" it('should have called the mocked API first', (result) => {",
" expect(JSON.stringify(result)).toEqual(JSON.stringify(call($2.$1, $3)));",
" });",
"${4}",
" // Insert test for default nextAction (if any)",
"${4}",
" it('and then nothing', (result) => {",
" expect(result).toBeUndefined();",
" });",
"});",
"${4}",
"describe('When testing the saga without a nextAction and with a response from the api', () => {",
" const it = sagaHelper($1(action));",
"${4}",
" it('should have called the mocked API first', (result) => {",
" expect(JSON.stringify(result)).toEqual(JSON.stringify(call($2.$1, $3)));",
"${4}",
" return response;",
" });",
"${4}",
" // Insert test for default nextAction (if any)",
"${4}",
" it('and then nothing', (result) => {",
" expect(result).toBeUndefined();",
" });",
"});",
"${4}",
"describe('When testing the saga with a nextAction and without a response from the api', () => {",
" const it = sagaHelper($1(actionWithNextAction));",
"${4}",
" it('should have called the mocked API first', (result) => {",
" expect(JSON.stringify(result)).toEqual(JSON.stringify(call($2.$1, $3)));",
" });",
"${4}",
" it('and then trigger an action', (result) => {",
" expect(result).toEqual(put({ ...nextAction, payload: {} }));",
" });",
"${4}",
" it('and then nothing', (result) => {",
" expect(result).toBeUndefined();",
" });",
"});",
"${4}",
"describe('When testing the saga with a nextAction and with a response from the api', () => {",
" const it = sagaHelper($1(actionWithNextAction));",
"${4}",
" it('should have called the mocked API first', (result) => {",
" expect(JSON.stringify(result)).toEqual(JSON.stringify(call($2.$1, $3)));",
"${4}",
" return response;",
" });",
"${4}",
" it('and then trigger an action', (result) => {",
" expect(result).toEqual(put({ ...nextAction, payload: response }));",
" });",
"${4}",
" it('and then nothing', (result) => {",
" expect(result).toBeUndefined();",
" });",
"});",
"${4}",
"describe('When testing the saga when an error is thrown from the api', () => {",
" const it = sagaHelper($1(action));",
" const errorMessage = 'Something went wrong';",
"${4}",
" it('should have called the mocked API first', (result) => {",
" expect(JSON.stringify(result)).toEqual(JSON.stringify(call($2.$1, $3)));",
"${4}",
" return new Error(errorMessage);",
" });",
"${4}",
" it('and then trigger an error action with the error message', (result) => {",
" expect(result).toEqual(",
"put({",
" type: 'logError',",
" payload: {",
" error: app.createError(errorMessage),",
" date: expect.any(Number),",
" },",
"}),",
" );",
" });",
"${4}",
" it('and then nothing', (result) => {",
" expect(result).toBeUndefined();",
" });",
"});"
]
},
"Blank string literal": {
"prefix": "str",
"body": ["`${$1}`"]
},
"Blank ref": {
"prefix": "ref",
"body": ["ref={(c) => {", " this.$1 = c;", "}}"]
}
}