Created
April 27, 2022 18:37
-
-
Save tanner-west/ca78fb065a65edfff0666972fdc88356 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import '@testing-library/jest-native/extend-expect'; | |
import 'react-native'; | |
import 'jest-enzyme'; | |
import Adapter from '@wojtekmaj/enzyme-adapter-react-17'; | |
import Enzyme from 'enzyme'; | |
/** | |
* Set up DOM in node.js environment for Enzyme to mount to | |
*/ | |
const {JSDOM} = require('jsdom'); | |
const jsdom = new JSDOM('<!doctype html><html><body></body></html>', { | |
url: 'http://localhost/', | |
}); | |
const {window} = jsdom; | |
function copyProps(src, target) { | |
Object.defineProperties(target, { | |
...Object.getOwnPropertyDescriptors(src), | |
...Object.getOwnPropertyDescriptors(target), | |
}); | |
} | |
global.window = window; | |
global.document = window.document; | |
global.navigator = { | |
userAgent: 'node.js', | |
}; | |
copyProps(window, global); | |
// suppress the '<View /> is using incorrect casing' warning | |
console.error = (error: any) => { | |
return error.includes('<View /> is using incorrect casing') ? null : error; | |
}; | |
// suppress the '<Text /> is using incorrect casing' warning | |
console.error = (error: any) => { | |
return error.includes('<Text /> is using incorrect casing') ? null : error; | |
}; | |
/** | |
* Set up Enzyme to mount to DOM, simulate events, | |
* and inspect the DOM in tests. | |
*/ | |
Enzyme.configure({adapter: new Adapter()}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment