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

jest snapshot serializer importing from 'dist' in version 0.7.2 #963

Closed
sidhu663 opened this issue May 22, 2018 · 1 comment
Closed

jest snapshot serializer importing from 'dist' in version 0.7.2 #963

sidhu663 opened this issue May 22, 2018 · 1 comment

Comments

@sidhu663
Copy link

The problem
I'm not 100% sure this is a bug but I think it probably is:
Given the following config (without using react-native-web babel plugin, using webpack 2):

// jest.config.js
{
  snapshotSerializers: ['enzyme-to-json/serializer', 'react-native-web/jest/serializer'],
  "transformIgnorePatterns": ["node_modules/(?!react-native-web)"],
  "moduleNameMapper": {
    "react-native": "<rootDir>/node_modules/react-native-web"
  },
}

Jest snapshots fail since the jest serializer is using StyleSheet from const { StyleSheet } = require('../dist');, whereas the components render using the ES6 StyleSheet built by webpack resulting in 2 different registries.

How to reproduce
Test case:

Steps to reproduce:
1.
2.
3.

Expected behavior
A clear and concise description of what you expected to happen.

Environment (include versions). Did this work in previous versions?

  • OS: osX
  • Device:
  • Browser:
  • React Native for Web (version): 0.7.2
  • React (version): 16.2

Additional context
Add any other context about the problem here.

@necolas
Copy link
Owner

necolas commented May 22, 2018

Yeah sounds right.

Related to #928

What I'm thinking of doing is removing the serializer and making StyleSheet.create the identity function when NODE_ENV==='test'. That will be simpler (and work for either cjs or esm) and retain the array of styles in the snapshot. Eventually can provide this as part of a jest preset like React Native's that does things like mock out View too.

necolas added a commit that referenced this issue Jun 4, 2018
A simple Jest preset that configures module mapping and produces
human-readable styles (i.e., not converted to numeric form).

Fix #928
Fix #963
@necolas necolas closed this as completed in 9ec8930 Jun 4, 2018
necolas added a commit that referenced this issue Jun 4, 2018
A simple Jest preset that configures module mapping and produces
human-readable styles (i.e., not converted to numeric form).

Fix #928
Fix #963
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants