Skip to content

Commit

Permalink
[change] introduce Jest preset
Browse files Browse the repository at this point in the history
A simple Jest preset that configures module mapping and produces
human-readable styles (i.e., not converted to numeric form).

Fix #928
Fix #963
  • Loading branch information
necolas committed Jun 4, 2018
1 parent 4f92168 commit 8f0c39c
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 403 deletions.
9 changes: 9 additions & 0 deletions packages/react-native-web/jest-preset.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"moduleNameMapper": {
"^react-native$": "<rootDir>/node_modules/react-native-web/dist/cjs"
},
"setupFiles": [
"<rootDir>/node_modules/react-native-web/jest/setup.js"
],
"testEnvironment": "jsdom"
}

This file was deleted.

92 changes: 0 additions & 92 deletions packages/react-native-web/jest/__tests__/serializer-test.js

This file was deleted.

6 changes: 0 additions & 6 deletions packages/react-native-web/jest/serializer.js

This file was deleted.

18 changes: 18 additions & 0 deletions packages/react-native-web/jest/setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/* eslint-env jasmine, jest */

'use strict';

global.__DEV__ = true;

const mockEmptyObject = {};

// Make sure snapshots contain the original style objects
jest.mock('../dist/cjs/modules/ReactNativePropRegistry', () => ({
register: id => id,
getByID: () => mockEmptyObject
}));

jest.mock('../dist/modules/ReactNativePropRegistry', () => ({
register: id => id,
getByID: () => mockEmptyObject
}));
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const React = require('react');
import React from 'react';
import { StyleSheet } from '../../packages/react-native-web/src';

function createSerializer(styleSheet) {
function flattenNodeStyles(node) {
Expand Down Expand Up @@ -53,4 +54,6 @@ function createSerializer(styleSheet) {
return { test, print };
}

module.exports = createSerializer;
const serializer = createSerializer(StyleSheet);

export default serializer;
7 changes: 3 additions & 4 deletions scripts/jest/setupFramework.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@

import Adapter from 'enzyme-adapter-react-16';
import Enzyme from 'enzyme';
import createSerializer from '../../packages/react-native-web/jest/createSerializer';
import { StyleSheet } from '../../packages/react-native-web/src';

const serializer = createSerializer(StyleSheet);
import serializer from './serializer';

Enzyme.configure({ adapter: new Adapter() });

// TODO: move off legacy serializer
expect.addSnapshotSerializer(serializer);

0 comments on commit 8f0c39c

Please sign in to comment.