Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Snapshot Test Import not working with babel-preset #1434

Closed
kgowru opened this issue Aug 15, 2016 · 4 comments
Closed

Snapshot Test Import not working with babel-preset #1434

kgowru opened this issue Aug 15, 2016 · 4 comments

Comments

@kgowru
Copy link

kgowru commented Aug 15, 2016

I'm trying a simple snapshot test. The component I'm testing uses another component from a module. The test fails when trying to import this unmocked module with:

Failure

Using Jest CLI v14.1.0, jasmine2, babel-jest, jest-react-native preset
 FAIL  js/app/SetupView/__tests__/SetupView-test.js (0s)
 Runtime Error
  - SyntaxError: Unexpected reserved word
        at transformAndBuildScript (../../../../../usr/local/lib/node_modules/jest-cli/node_modules/jest-runtime/build/transform.js:306:10)
        at Object.<anonymous> (js/app/SetupView/index.js:12:17)
        at Object.<anonymous> (js/app/SetupView/__tests__/SetupView-test.js:11:12)
1 test suite failed, 0 tests passed (0 total in 1 test suite, run time 2.419s)

Test

'use strict';
import 'react-native';
import React from 'react';

import SetupView from '../index';

import renderer from 'react-test-renderer';

describe('SetupView', ()=> {
  it('renders correctly', ()=>{
    const tree = renderer.create(
      <SetupView/>
    ).toJSON();
    expect(tree).toMatchSnapshot();
  })
});

SetupView Component

'use strict';

import React from 'react';
import {
  View,
  Text,
  TouchableHighlight,
  Image,
  Animated,
} from 'react-native';

import DataContainer from 'react.datacontainer'; //<---fails here
import DashboardSettings from './DashboardSettings';
.
.
.

package.json

"jest": {
    "globals": {
      "__DEV__": true
    },
    "collectCoverage": false,
    "verbose": true,
    "preset": "jest-react-native",
    "modulePathIgnorePatterns": [
      "node_modules/react-native/node_modules/yeoman-generator",
      "node_modules/react-native/node_modules/fbjs"
    ],
    "unmockedModulePathPatterns": [
      "react.datacontainer",
      "react.data",
      "react.base.theme",
      "react.layout"
    ]
  }

FYI, I have a .babelrc file in my root directory pointing to the react-native preset and the test runs but fails if I comment line 12 out since DataContainer is undefined.

@cpojer
Copy link
Member

cpojer commented Aug 15, 2016

Can you try jest --no-cache? If you changed your babelrc before the last invocation, we might not update the cache properly.

If that does not work please create a repo on github that I can npm install and npm test to troubleshoot.

Tip: you don't need unmockedModulePathPatterns when using the react-native-preset because automocking will be disabled anyway.

@kgowru
Copy link
Author

kgowru commented Aug 16, 2016

That didn't work for me. It seems like the issue is with importing the node_module react.datacontainer. After digging in some more, I believe the jest preset is not compiling the node_modules written in es6.

Unfortunately, I can't create a repo at this time. But if it helps further here's what 'react.datacontainer' module looks like. https://github.com/ForceDotComLabs/react.force.datacontainer

@cpojer
Copy link
Member

cpojer commented Aug 16, 2016

You can enable preprocessing for this module via this config option: http://facebook.github.io/jest/docs/tutorial-react-native.html#preprocessorignorepatterns-customization

If you'd like, you can also create an issue on this project's github page to ask them to precompile their dependencies and publish build files on npm.

@cpojer cpojer closed this as completed Aug 16, 2016
@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 14, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants