Skip to content

Commit

Permalink
Fixing jest
Browse files Browse the repository at this point in the history
  • Loading branch information
hsjoberg committed May 31, 2019
1 parent b3f688b commit 20ce86d
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 4 deletions.
2 changes: 1 addition & 1 deletion __tests__/App-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import App from "../src/App";
import renderer from "react-test-renderer";

jest.mock("react-native-camera", () => {
return require("../mocks/Camera");
return require("../mocks/react-native-camera");
});


Expand Down
8 changes: 8 additions & 0 deletions assetsTransformer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// https://github.com/facebook/jest/issues/2663#issuecomment-317109798
const path = require('path');

module.exports = {
process(src, filename, config, options) {
return 'module.exports = ' + JSON.stringify(path.basename(filename)) + ';';
},
};
11 changes: 9 additions & 2 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@ module.exports = {
preset: 'react-native',
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
transformIgnorePatterns: [
"node_modules/(?!react-native|@shoutem|react-clone-referenced-element|native-base-shoutem-theme|react-native-camera)"
]
"node_modules/(?!react-native|@shoutem|react-clone-referenced-element|native-base-shoutem-theme|react-native-camera|@react-navigation|react-navigation-tabs)"
],
"setupFiles": [
"./jestSetup.js"
],
"moduleNameMapper": {
"\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "<rootDir>/assetsTransformer.js",
"\\.(css|less)$": "<rootDir>/assetsTransformer.js"
}
}
16 changes: 16 additions & 0 deletions jestSetup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// https://github.com/kmagiera/react-native-gesture-handler/issues/344#issuecomment-450859200
import { NativeModules as RNNativeModules } from "react-native";

RNNativeModules.UIManager = RNNativeModules.UIManager || {};
RNNativeModules.UIManager.RCTView = RNNativeModules.UIManager.RCTView || {};
RNNativeModules.RNGestureHandlerModule = RNNativeModules.RNGestureHandlerModule || {
State: { BEGAN: "BEGAN", FAILED: "FAILED", ACTIVE: "ACTIVE", END: "END" },
attachGestureHandler: jest.fn(),
createGestureHandler: jest.fn(),
dropGestureHandler: jest.fn(),
updateGestureHandler: jest.fn(),

};
RNNativeModules.PlatformConstants = RNNativeModules.PlatformConstants || {
forceTouchAvailable: false
};
File renamed without changes.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start",
"test": "jest",
"test-update-snapshot": "jest -u --transformIgnorePatterns \"node_modules/(?!react-native|native-base|native-base-shoutem-theme)\""
"test-update-snapshot": "jest -u"
},
"dependencies": {
"@types/qrcode": "1.3.3",
Expand Down

0 comments on commit 20ce86d

Please sign in to comment.