Created
July 30, 2018 11:13
-
-
Save axelnormand/27110f3f85801fa760287489378006c0 to your computer and use it in GitHub Desktop.
React Native Jest
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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