@@ -510,7 +510,7 @@ export const withState = <WrappedProps extends InjectedProps>(
510
510
};
511
511
512
512
` ` `
513
- <details><summary>show usage </summary><p>
513
+ <details style="background: #f6f8fa;border-radius: 3px;" ><summary style="padding: 6px 12px;border-radius: 3px;"><i>Click to expand</i> </summary><p>
514
514
515
515
` ` ` tsx
516
516
import * as React from ' react' ;
@@ -594,7 +594,7 @@ export const withErrorBoundary = <WrappedProps extends InjectedProps>(
594
594
};
595
595
596
596
` ` `
597
- <details><summary>show usage </summary><p>
597
+ <details style="background: #f6f8fa;border-radius: 3px;" ><summary style="padding: 6px 12px;border-radius: 3px;"><i>Click to expand</i> </summary><p>
598
598
599
599
` ` ` tsx
600
600
import * as React from ' react' ;
@@ -658,7 +658,7 @@ export const SFCCounterConnected = connect(mapStateToProps, {
658
658
})(SFCCounter );
659
659
660
660
` ` `
661
- <details><summary>show usage </summary><p>
661
+ <details style="background: #f6f8fa;border-radius: 3px;" ><summary style="padding: 6px 12px;border-radius: 3px;"><i>Click to expand</i> </summary><p>
662
662
663
663
` ` ` tsx
664
664
import * as React from ' react' ;
@@ -698,7 +698,7 @@ export const SFCCounterConnectedVerbose =
698
698
connect (mapStateToProps , mapDispatchToProps )(SFCCounter );
699
699
700
700
` ` `
701
- <details><summary>show usage </summary><p>
701
+ <details style="background: #f6f8fa;border-radius: 3px;" ><summary style="padding: 6px 12px;border-radius: 3px;"><i>Click to expand</i> </summary><p>
702
702
703
703
` ` ` tsx
704
704
import * as React from ' react' ;
@@ -738,7 +738,7 @@ export const SFCCounterConnectedExtended = connect(mapStateToProps, {
738
738
})(SFCCounter );
739
739
740
740
` ` `
741
- <details><summary>show usage </summary><p>
741
+ <details style="background: #f6f8fa;border-radius: 3px;" ><summary style="padding: 6px 12px;border-radius: 3px;"><i>Click to expand</i> </summary><p>
742
742
743
743
` ` ` tsx
744
744
import * as React from ' react' ;
@@ -852,7 +852,7 @@ export const add = (amount: number) => action(ADD, amount);
852
852
// });
853
853
854
854
` ` `
855
- <details><summary>show usage </summary><p>
855
+ <details style="background: #f6f8fa;border-radius: 3px;" ><summary style="padding: 6px 12px;border-radius: 3px;"><i>Click to expand</i> </summary><p>
856
856
857
857
` ` ` tsx
858
858
import store from ' ../../store' ;
@@ -1215,14 +1215,16 @@ export const SFCCounterConnectedVerbose =
1215
1215
- Add additional ` react ` specific rules: ` npm i - D tslint - react ` https://github.com/palantir/tslint-react
1216
1216
- Overwritten some defaults for more flexibility
1217
1217
1218
- ` ` ` js
1218
+ <details style="background: #f6f8fa;border-radius: 3px;"><summary style="padding: 6px 12px;border-radius: 3px;"><i>Click to expand</i></summary><p>
1219
+
1220
+ ` ` ` tsx
1219
1221
{
1220
1222
" extends" : [" tslint:recommended" , " tslint-react" ],
1221
1223
" rules" : {
1222
1224
" arrow-parens" : false ,
1223
1225
" arrow-return-shorthand" : [false ],
1224
1226
" comment-format" : [true , " check-space" ],
1225
- " import-blacklist" : [true , " rxjs " ],
1227
+ " import-blacklist" : [true ],
1226
1228
" interface-over-type-literal" : false ,
1227
1229
" interface-name" : false ,
1228
1230
" max-line-length" : [true , 120 ],
@@ -1234,6 +1236,7 @@ export const SFCCounterConnectedVerbose =
1234
1236
" no-import-side-effect" : [true ],
1235
1237
" no-inferrable-types" : [true , " ignore-params" , " ignore-properties" ],
1236
1238
" no-invalid-this" : [true , " check-function-in-method" ],
1239
+ " no-namespace" : false ,
1237
1240
" no-null-keyword" : false ,
1238
1241
" no-require-imports" : false ,
1239
1242
" no-submodule-imports" : [true , " @src" , " rxjs" ],
@@ -1247,26 +1250,38 @@ export const SFCCounterConnectedVerbose =
1247
1250
" prefer-method-signature" : false ,
1248
1251
" prefer-template" : [true , " allow-single-concat" ],
1249
1252
" quotemark" : [true , " single" , " jsx-double" ],
1250
- " semicolon" : [true , " always" ],
1251
- " trailing-comma" : [true , {
1252
- " singleline" : " never" ,
1253
- " multiline" : {
1254
- " objects" : " always" ,
1255
- " arrays" : " always" ,
1256
- " functions" : " never" ,
1257
- " typeLiterals" : " ignore"
1258
- },
1259
- " esSpecCompliant" : true
1260
- }],
1253
+ " semicolon" : [true , " always" , " ignore-bound-class-methods" ],
1254
+ " trailing-comma" : [
1255
+ true ,
1256
+ {
1257
+ " singleline" : " never" ,
1258
+ " multiline" : {
1259
+ " objects" : " always" ,
1260
+ " arrays" : " always" ,
1261
+ " functions" : " ignore" ,
1262
+ " typeLiterals" : " ignore"
1263
+ },
1264
+ " esSpecCompliant" : true
1265
+ }
1266
+ ],
1261
1267
" triple-equals" : [true , " allow-null-check" ],
1262
1268
" type-literal-delimiter" : true ,
1263
- " typedef" : [true ," parameter" , " property-declaration" ],
1264
- " variable-name" : [true , " ban-keywords" , " check-format" , " allow-pascal-case" , " allow-leading-underscore" ],
1269
+ " typedef" : [true , " parameter" , " property-declaration" ],
1270
+ " variable-name" : [
1271
+ true ,
1272
+ " ban-keywords" ,
1273
+ " check-format" ,
1274
+ " allow-pascal-case" ,
1275
+ " allow-leading-underscore"
1276
+ ],
1265
1277
// tslint-react
1278
+ " jsx-no-multiline-js" : false ,
1266
1279
" jsx-no-lambda" : false
1267
1280
}
1268
1281
}
1282
+
1269
1283
` ` `
1284
+ </p></details>
1270
1285
1271
1286
[⇧ back to top](#table-of-contents)
1272
1287
@@ -1276,11 +1291,13 @@ export const SFCCounterConnectedVerbose =
1276
1291
` npm i - D jest ts - jest @types / jest `
1277
1292
1278
1293
#### jest.config.json
1279
- ` ` ` json
1294
+ <details style="background: #f6f8fa;border-radius: 3px;"><summary style="padding: 6px 12px;border-radius: 3px;"><i>Click to expand</i></summary><p>
1295
+
1296
+ ` ` ` tsx
1280
1297
{
1281
1298
" verbose" : true ,
1282
1299
" transform" : {
1283
- " .(ts|tsx)" : " ./node_modules/ ts-jest/preprocessor.js "
1300
+ " .(ts|tsx)" : " ts-jest"
1284
1301
},
1285
1302
" testRegex" : " (/spec/.*|\\ .(test|spec))\\ .(ts|tsx|js)$" ,
1286
1303
" moduleFileExtensions" : [" ts" , " tsx" , " js" ],
@@ -1290,19 +1307,29 @@ export const SFCCounterConnectedVerbose =
1290
1307
" globals" : {
1291
1308
" window" : {},
1292
1309
" ts-jest" : {
1293
- " tsConfigFile " : " ./tsconfig.json"
1310
+ " tsConfig " : " ./tsconfig.json"
1294
1311
}
1295
1312
},
1296
- " setupFiles" : [
1297
- " ./jest.stubs.js"
1298
- ],
1299
- " setupTestFrameworkScriptFile" : " ./jest.tests.js"
1313
+ " setupFiles" : [" ./jest.stubs.js" ],
1314
+ " testURL" : " http://localhost/"
1300
1315
}
1316
+
1301
1317
` ` `
1318
+ </p></details>
1302
1319
1303
1320
#### jest.stubs.js
1304
- ` ` ` js
1321
+ <details style="background: #f6f8fa;border-radius: 3px;"><summary style="padding: 6px 12px;border-radius: 3px;"><i>Click to expand</i></summary><p>
1322
+
1323
+ ` ` ` tsx
1305
1324
// Global/Window object Stubs for Jest
1325
+ window .matchMedia = window .matchMedia || function () {
1326
+ return {
1327
+ matches: false ,
1328
+ addListener : function () { },
1329
+ removeListener : function () { },
1330
+ };
1331
+ };
1332
+
1306
1333
window .requestAnimationFrame = function (callback ) {
1307
1334
setTimeout (callback );
1308
1335
};
@@ -1313,22 +1340,9 @@ window.localStorage = {
1313
1340
};
1314
1341
1315
1342
Object .values = () => [];
1316
- ` ` `
1317
-
1318
- [⇧ back to top](#table-of-contents)
1319
-
1320
- ## Enzyme
1321
-
1322
- > Installation
1323
- ` npm i - D enzyme enzyme - adapter - react - 16 @types / enzyme `
1324
-
1325
- #### jest.tests.js
1326
- ` ` ` js
1327
- import { configure } from ' enzyme' ;
1328
- import Adapter from ' enzyme-adapter-react-16' ;
1329
1343
1330
- configure ({ adapter: new Adapter () });
1331
1344
` ` `
1345
+ </p></details>
1332
1346
1333
1347
[⇧ back to top](#table-of-contents)
1334
1348
@@ -1364,34 +1378,33 @@ configure({ adapter: new Adapter() });
1364
1378
- Install [ ` tslib ` ](https://www.npmjs.com/package/tslib) to cut on bundle size, by using external runtime helpers instead of adding them inline: ` npm i tslib `
1365
1379
- Example "paths" setup for baseUrl relative imports with Webpack
1366
1380
1367
- ` ` ` js
1381
+ <details style="background: #f6f8fa;border-radius: 3px;"><summary style="padding: 6px 12px;border-radius: 3px;"><i>Click to expand</i></summary><p>
1382
+
1383
+ ` ` ` tsx
1368
1384
{
1369
1385
" compilerOptions" : {
1370
- " baseUrl" : " ./" , // enables project relative paths config
1371
- " paths" : { // define paths mappings
1372
- " @src/*" : [" src/*" ] // will enable import aliases -> import { ... } from '@src/components'
1373
- // WARNING: Add this to your webpack config -> resolve: { alias: { '@src': PATH_TO_SRC } }
1374
- // "redux": ["typings/redux"], // use an alternative type-definitions instead of the included one
1386
+ " baseUrl" : " ./" , // relative paths base
1387
+ " paths" : {
1388
+ // "@src/*": ["src/*"] // will enable import aliases -> import { ... } from '@src/components'
1389
+ // WARNING: Require to add this to your webpack config -> resolve: { alias: { '@src': PATH_TO_SRC } }
1390
+ // "redux": ["typings/redux"], // override library types with your alternative type-definitions in typings folder
1375
1391
},
1376
1392
" outDir" : " dist/" , // target for compiled files
1377
1393
" allowSyntheticDefaultImports" : true , // no errors with commonjs modules interop
1378
1394
" esModuleInterop" : true , // enable to do "import React ..." instead of "import * as React ..."
1379
1395
" allowJs" : true , // include js files
1380
1396
" checkJs" : true , // typecheck js files
1381
1397
" declaration" : false , // don't emit declarations
1382
- " emitDecoratorMetadata" : true , // only if using decorators
1383
- " experimentalDecorators" : true , // only if using decorators
1398
+ " emitDecoratorMetadata" : true , // include only if using decorators
1399
+ " experimentalDecorators" : true , // include only if using decorators
1384
1400
" forceConsistentCasingInFileNames" : true ,
1385
1401
" importHelpers" : true , // importing transpilation helpers from tslib
1386
1402
" noEmitHelpers" : true , // disable inline transpilation helpers in each file
1387
- " jsx" : " react" , // translate JSX
1388
- " lib" : [
1389
- " dom" ,
1390
- " es2016" ,
1391
- " es2017.object"
1392
- ],
1403
+ " jsx" : " react" , // transform JSX
1404
+ " lib" : [" dom" , " es2017" ], // you will need to include polyfills for es2017 manually
1405
+ " types" : [" jest" ], // which global types to use
1393
1406
" target" : " es5" , // "es2015" for ES6+ engines
1394
- " module" : " commonjs " , // "es2015" for tree-shaking
1407
+ " module" : " es2015 " , // "es2015" for tree-shaking
1395
1408
" moduleResolution" : " node" ,
1396
1409
" noEmitOnError" : true ,
1397
1410
" noFallthroughCasesInSwitch" : true ,
@@ -1401,15 +1414,12 @@ configure({ adapter: new Adapter() });
1401
1414
" removeComments" : true ,
1402
1415
" sourceMap" : true
1403
1416
},
1404
- " include" : [
1405
- " src/**/*"
1406
- ],
1407
- " exclude" : [
1408
- " node_modules" ,
1409
- " src/**/*.spec.*"
1410
- ]
1417
+ " include" : [" src" , " typings" ],
1418
+ " exclude" : [" src/**/*.spec.*" ]
1411
1419
}
1420
+
1412
1421
` ` `
1422
+ </p></details>
1413
1423
1414
1424
[⇧ back to top](#table-of-contents)
1415
1425
0 commit comments