Skip to content

Instantly share code, notes, and snippets.

@axelnormand
Created July 30, 2018 11:13
Show Gist options
  • Save axelnormand/27110f3f85801fa760287489378006c0 to your computer and use it in GitHub Desktop.
Save axelnormand/27110f3f85801fa760287489378006c0 to your computer and use it in GitHub Desktop.
React Native Jest
// Setup for use with enzyme
// Patching console.error so test will fail
const Enzyme = require('enzyme');
const Adapter = require('enzyme-adapter-react-16');
Enzyme.configure({ adapter: new Adapter() });
//fix redux saga test plan which needs setTimeout on window
global.window.setTimeout = global.setTimeout;
// Ignore console.log whilst running tests
console.log = () => {};
// Throw error upon console.error to fail test
// Ignore a few console.error whilst running tests
const suppressedErrors = /(React\.createElement: type is invalid)/;
const realConsoleError = console.error;
console.error = message => {
if (message.match(suppressedErrors)) {
return;
}
const msg = `Console.Error in Test: "${message}"`
debugger;
realConsoleError(msg);
throw new Error(msg);
};
// Fix "BlobModule.addNetworkingHandler is not a function" when upgrading to react native 0.54
import { NativeModules } from "react-native";
NativeModules.BlobModule = {
...NativeModules.BlobModule,
addNetworkingHandler: jest.fn()
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment