Coder Social home page Coder Social logo

Comments (9)

joncursi avatar joncursi commented on June 7, 2024

Note that my setup.js file for mocha already denotes pre-transpilation of this package with Babel before running the test, yet it still fails.

// 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');

from ex-navigation.

joncursi avatar joncursi commented on June 7, 2024

Update: I've isolated the failures to components that use the @withNavigation decorator. There needs to be a way to mock this somehow for the tests, but I'm not sure how.

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.

import { StackNavigation } from '@exponent/ex-navigation';
import { withNavigation } from '@exponent/ex-navigation';
import { createRouter } from '@exponent/ex-navigation';

from ex-navigation.

joncursi avatar joncursi commented on June 7, 2024

Theoretically this issue would be resolved if we could connect to ex-navigation's redux store, as that would eliminate the need for @withNavigation altogether. Not necessarily true per Update 2 above.

Related:
#44
#39

from ex-navigation.

skevy avatar skevy commented on June 7, 2024

@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

from ex-navigation.

sibelius avatar sibelius commented on June 7, 2024

@joncursi did u solve ur issue?

from ex-navigation.

damusnet avatar damusnet commented on June 7, 2024

This did the trick for me to run my mocha tests again after installing @exponent/ex-navigation:

mockery.registerMock('@exponent/ex-navigation', {
  createRouter: () => {},
});

Not fully published yet, but see this other issue for more info.

from ex-navigation.

sibelius avatar sibelius commented on June 7, 2024

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

from ex-navigation.

damusnet avatar damusnet commented on June 7, 2024

Agreed, however lelandrichardson/react-native-mock only mocks react-native core native modules, not third party libraries, and yes, while Jest has become really nice to work with thanks to its handy mocking feature, you can't alway make the switch from your testing library (Mocha in this case).

from ex-navigation.

sibelius avatar sibelius commented on June 7, 2024

there are some really good codemods to help in this case

https://github.com/skovhus/jest-codemods

from ex-navigation.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.