-
Notifications
You must be signed in to change notification settings - Fork 201
Tests Fail for Imported Components #45
Comments
Note that my // setup.js
import fs from 'fs';
import path from 'path';
import register from 'babel-core/register';
// Ignore all node_modules except these
const modulesToCompile = [
'@exponent/ex-navigation',
'react-clone-referenced-element',
'react-native',
'react-native-material-design',
'react-native-mock',
].map((moduleName) => new RegExp(`/node_modules/${moduleName}`));
const rcPath = path.join(__dirname, '../../../..', '.babelrc');
const source = fs.readFileSync(rcPath).toString();
const config = JSON.parse(source);
config.ignore = (filename) => {
if ((/\/node_modules\//).test(filename)) {
const matches = modulesToCompile.filter((regex) => regex.test(filename));
const shouldIgnore = matches.length === 0;
return shouldIgnore;
}
return false;
};
register(config);
// Setup mocks
require('react-native-mock/mock'); |
import { connect } from 'react-redux';
import { withNavigation } from '@exponent/ex-navigation';
@withNavigation
export class TheComponent extends Component {
...
}
export default connect(mapStateToProps, mapDispatchToProps)(TheComponent); Update 2: I lied. After doing some more debugging, I've come to the conclusion that pretty much every exportable by this library seems to cause the transpile error.
|
@joncursi is there any way you could provide a small example repo that isolates this case? we don't use mocha @ exponent, so it's difficult for me to test this without code |
@joncursi did u solve ur issue? |
This did the trick for me to run my mocha tests again after installing
Not fully published yet, but see this other issue for more info. |
I think https://github.com/lelandrichardson/react-native-mock provides a lot of mocked versions of the component Otherwise, jest automock all the component itself, making in much easier to test |
Agreed, however |
there are some really good codemods to help in this case |
When running mocha tests on components that contain
StackNavigation
components somewhere in the child tree, the test will error out. Here's an example of a valid Enzyme test failing due to inability to process this package:The text was updated successfully, but these errors were encountered: