Skip to content

Commit 17af01e

Browse files
committed
init tests
1 parent da680f2 commit 17af01e

File tree

9 files changed

+3157
-1400
lines changed

9 files changed

+3157
-1400
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
dist
22
node_modules
3-
.DS_Store
3+
.DS_Store
4+
.jest

.npmignore

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,9 @@ tsconfig.json
22
src
33
example
44
.DS_Store
5-
img
5+
img
6+
.jest
7+
jest
8+
jest.config.js
9+
.circleci
10+
__tests__

jest.config.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
module.exports = {
2+
verbose: true,
3+
preset: "react-native",
4+
transform: {
5+
"\\.jsx?$": "<rootDir>/node_modules/react-native/jest/preprocessor.js",
6+
"^.+\\.tsx?$": "ts-jest",
7+
},
8+
modulePaths: ["<rootDir>"],
9+
globals: {
10+
"ts-jest": {
11+
babelConfig: true,
12+
diagnostics: false,
13+
},
14+
},
15+
transformIgnorePatterns: ["node_modules/(?!react-native|react-native-gesture-handler)/"],
16+
modulePathIgnorePatterns: [
17+
"example/node_modules/react-native/",
18+
"example/node_modules/react-native-gesture-handler/",
19+
],
20+
testPathIgnorePatterns: ["node_modules", "dist"],
21+
setupFiles: ["<rootDir>/jest/setup.js"],
22+
setupFilesAfterEnv: ["<rootDir>/jest/setupEnzymeAfterEnv.js"],
23+
cacheDirectory: ".jest/cache",
24+
};

jest/setup.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { NativeModules as RNNativeModules } from "react-native";
2+
RNNativeModules.UIManager = RNNativeModules.UIManager || {};
3+
RNNativeModules.UIManager.RCTView = RNNativeModules.UIManager.RCTView || {};
4+
RNNativeModules.RNGestureHandlerModule = RNNativeModules.RNGestureHandlerModule || {
5+
State: { BEGAN: "BEGAN", FAILED: "FAILED", ACTIVE: "ACTIVE", END: "END" },
6+
attachGestureHandler: jest.fn(),
7+
createGestureHandler: jest.fn(),
8+
dropGestureHandler: jest.fn(),
9+
updateGestureHandler: jest.fn(),
10+
};
11+
RNNativeModules.PlatformConstants = RNNativeModules.PlatformConstants || {
12+
forceTouchAvailable: false,
13+
};

jest/setupEnzymeAfterEnv.js

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import "react-native";
2+
import "jest-enzyme";
3+
import Adapter from "enzyme-adapter-react-16";
4+
import Enzyme from "enzyme";
5+
6+
/**
7+
* Set up DOM in node.js environment for Enzyme to mount to
8+
*/
9+
const { JSDOM } = require("jsdom");
10+
11+
const jsdom = new JSDOM("<!doctype html><html><body></body></html>");
12+
const { window } = jsdom;
13+
14+
function copyProps(src, target) {
15+
Object.defineProperties(target, {
16+
...Object.getOwnPropertyDescriptors(src),
17+
...Object.getOwnPropertyDescriptors(target),
18+
});
19+
}
20+
21+
global.window = window;
22+
global.document = window.document;
23+
global.navigator = {
24+
userAgent: "node.js",
25+
};
26+
copyProps(window, global);
27+
28+
/**
29+
* Set up Enzyme to mount to DOM, simulate events,
30+
* and inspect the DOM in tests.
31+
*/
32+
Enzyme.configure({ adapter: new Adapter() });
33+
34+
/**
35+
* Ignore some expected warnings
36+
* see: https://jestjs.io/docs/en/tutorial-react.html#snapshot-testing-with-mocks-enzyme-and-react-16
37+
* see https://github.com/Root-App/react-native-mock-render/issues/6
38+
*/
39+
40+
const originalConsoleError = console.error; // eslint-disable-line
41+
// eslint-disable-next-line
42+
console.error = message => {
43+
if (message.startsWith("Warning:")) {
44+
return;
45+
}
46+
47+
originalConsoleError(message);
48+
};
49+
50+
const originalConsoleLog = console.log; // eslint-disable-line
51+
// eslint-disable-next-line
52+
console.log = (descriptor, message) => {
53+
if (
54+
descriptor.startsWith("Warning:") ||
55+
((typeof message === "string" || message instanceof String) && message.startsWith("Warning:"))
56+
) {
57+
return;
58+
}
59+
60+
if (
61+
descriptor.startsWith("TypeError:") ||
62+
((typeof message === "string" || message instanceof String) && message.startsWith("TypeError:"))
63+
) {
64+
return;
65+
}
66+
67+
originalConsoleLog(message);
68+
};

package.json

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,24 @@
2626
"react-native-gesture-handler": ">=1.3.0"
2727
},
2828
"devDependencies": {
29+
"@types/enzyme": "^3.10.3",
30+
"@types/enzyme-adapter-react-16": "^1.0.5",
2931
"@types/jest": "^24.0.18",
3032
"@types/lodash": "^4.14.138",
3133
"@types/react": "^16.9.2",
3234
"@types/react-native": "^0.60.9",
35+
"babel-jest": "^24.9.0",
36+
"enzyme": "^3.10.0",
37+
"enzyme-adapter-react-16": "^1.14.0",
3338
"jest": "^24.9.0",
34-
"typescript": "^3.6.2"
39+
"jest-enzyme": "^7.1.1",
40+
"react": ">=16.8.0",
41+
"react-dom": "^16.9.0",
42+
"react-native": "^0.60.5",
43+
"react-native-gesture-handler": "^1.4.1",
44+
"react-test-renderer": "^16.9.0",
45+
"ts-jest": "^24.1.0",
46+
"typescript": "^3.6.2",
47+
"weak": "^1.0.1"
3548
}
3649
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import React from "react";
2+
import { Animated } from "react-native";
3+
import { mount } from "enzyme";
4+
5+
import GesturePath from "../GesturePath";
6+
7+
describe("<GesturePath />", () => {
8+
it("renders 3 coordinate points", () => {
9+
const wrapper = mount(
10+
<GesturePath path={[{ x: 0, y: 0 }, { x: 10, y: 0 }, { x: 20, y: 0 }]} />,
11+
);
12+
expect(wrapper.find(Animated.View)).toHaveLength(3);
13+
});
14+
});

tsconfig.json

Lines changed: 13 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,17 @@
11
{
22
"compilerOptions": {
3-
/* Basic Options */
4-
// "incremental": true, /* Enable incremental compilation */
5-
"target": "es5" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */,
6-
"module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */,
7-
"lib": ["es2015"] /* Specify library files to be included in the compilation. */,
8-
// "allowJs": true, /* Allow javascript files to be compiled. */
9-
// "checkJs": true, /* Report errors in .js files. */
10-
"jsx": "react" /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */,
11-
"declaration": true /* Generates corresponding '.d.ts' file. */,
12-
"declarationMap": true /* Generates a sourcemap for each corresponding '.d.ts' file. */,
13-
// "sourceMap": true, /* Generates corresponding '.map' file. */
14-
// "outFile": "./", /* Concatenate and emit output to single file. */
15-
"outDir": "dist" /* Redirect output structure to the directory. */,
16-
"rootDir": "src" /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */,
17-
// "composite": true, /* Enable project compilation */
18-
// "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
19-
// "removeComments": true, /* Do not emit comments to output. */
20-
// "noEmit": true /* Do not emit outputs. */,
21-
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
22-
// "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
23-
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
24-
25-
/* Strict Type-Checking Options */
26-
"strict": true /* Enable all strict type-checking options. */,
27-
"noImplicitAny": true /* Raise error on expressions and declarations with an implied 'any' type. */,
28-
// "strictNullChecks": true, /* Enable strict null checks. */
29-
// "strictFunctionTypes": true, /* Enable strict checking of function types. */
30-
// "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
31-
// "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
32-
// "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
33-
// "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
34-
35-
/* Additional Checks */
36-
// "noUnusedLocals": true, /* Report errors on unused locals. */
37-
// "noUnusedParameters": true, /* Report errors on unused parameters. */
38-
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
39-
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
40-
41-
/* Module Resolution Options */
42-
// "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
43-
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
44-
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
45-
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
46-
// "typeRoots": ["src"] /* List of folders to include type definitions from. */,
47-
// "types": ["index.d.ts"] /* Type declaration files to be included in compilation. */,
48-
"allowSyntheticDefaultImports": true /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */,
49-
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
50-
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
51-
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
52-
53-
/* Source Map Options */
54-
// "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
55-
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
56-
// "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
57-
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
58-
59-
/* Experimental Options */
60-
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
61-
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
3+
"target": "es5",
4+
"module": "commonjs",
5+
"lib": ["esnext"],
6+
"allowJs": false,
7+
"jsx": "react",
8+
"declaration": true,
9+
"declarationMap": true,
10+
"outDir": "dist",
11+
"rootDir": "src",
12+
"strict": true,
13+
"noImplicitAny": true,
14+
"allowSyntheticDefaultImports": true,
15+
"esModuleInterop": true
6216
}
63-
// "include": ["./src/**/*", "./typings/**/*"]
6417
}

0 commit comments

Comments
 (0)