To test the react-native redux connected(higher order) components,we need to use enzyme mount for accessing mapStateToProps,mapDispatchToProps etc...As enzyme mount api uses jsdom .Is mount supported in react-native or not?.
I went through different articles and it was mentioned that we can use mount for testing react-native redux connected components.
In my jest setup file I have given this piece of code.
/** jest setup file **/
import { configure } from "enzyme";
import EnzymeAdapter from "enzyme-adapter-react-16";
configure({ adapter: new EnzymeAdapter() });
/**
* Set up DOM in node.js environment for Enzyme to mount to
*/
const { JSDOM } = require("jsdom");
const jsdom = new JSDOM("");
const { window } = jsdom;
function copyProps(src: any, target: NodeJS.Global) {
Object.defineProperties(target, {
...Object.getOwnPropertyDescriptors(src),
...Object.getOwnPropertyDescriptors(target)
});
}
global.window = window;
global.document = window.document;
global.navigator = {
userAgent: "node.js"
};
copyProps(window, global);
const originalConsoleError = console.error;
console.error = (message: string) => {
if (message.startsWith("Warning:")) {
return;
}
originalConsoleError(message);
};
If I commented originalConsoleError method.,even though test case got passed we are getting this error.
console.error node_modules/react-dom/cjs/react-dom.development.js:506
Warning: <Text /> is using incorrect casing. Use PascalCase for React components, or lowercase for HTML elements.
in Text (created by Text)
in Text (at create-icon-set.js:92)
in Icon (created by Avatar)
in Avatar (created by WrapperComponent)
in WrapperComponent
Can we really use mount for testing react-native higherorder components.If not, how can we test using jest and enzyme?If yes, how to avoid these errors without suppressing it like originalConsoleError method?