Skip to content

Commit

Permalink
Remove enzyme
Browse files Browse the repository at this point in the history
  • Loading branch information
necolas committed Jun 26, 2020
1 parent 204c432 commit 7e724b2
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 393 deletions.
3 changes: 0 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@
"caniuse-api": "^3.0.0",
"cross-env": "^6.0.3",
"del-cli": "^3.0.0",
"enzyme": "^3.10.0",
"enzyme-adapter-react-16": "^1.14.0",
"enzyme-to-json": "^3.4.2",
"eslint": "^6.5.1",
"eslint-config-prettier": "^6.4.0",
"eslint-plugin-promise": "^4.2.1",
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,44 +1,5 @@
/* eslint-env jasmine, jest */

import React from 'react';
import ScrollView from '..';
import StyleSheet from '../../StyleSheet';
import View from '../../View';
import { mount, shallow } from 'enzyme';

describe('components/ScrollView', () => {
test('instance method setNativeProps', () => {
const instance = mount(<ScrollView />).instance();
expect(() => {
instance.setNativeProps();
}).not.toThrow();
});

test('"children" prop', () => {
const component = shallow(
<ScrollView>
<View testID="child" />
</ScrollView>
);
expect(component.find({ testID: 'child' }).length).toBe(1);

component.setProps({ stickyHeaderIndices: [4] });
expect(component.find({ testID: 'child' }).length).toBe(1);

component.setProps({ pagingEnabled: true });
expect(component.find({ testID: 'child' }).length).toBe(1);
});

test('"pagingEnabled" prop', () => {
const getStyleProp = (component, prop) => StyleSheet.flatten(component.prop('style'))[prop];

// false
const component = shallow(<ScrollView children={'Child'} />);
expect(getStyleProp(component, 'scrollSnapType')).toMatchSnapshot();

// true
component.setProps({ pagingEnabled: true });
expect(getStyleProp(component, 'scrollSnapType')).toMatchSnapshot();
expect(getStyleProp(component.children().childAt(0), 'scrollSnapAlign')).toMatchSnapshot();
});
test.skip('todo', () => {});
});
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* eslint-env jasmine, jest */

import React from 'react';
import { render } from '@testing-library/react';
import View from '../';
import { render } from '@testing-library/react';

describe('components/View', () => {
test('default', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`modules/createElement renders different DOM elements 1`] = `<span />`;
exports[`exports/createElement renders different DOM elements 1`] = `<span />`;

exports[`modules/createElement renders different DOM elements 2`] = `<main />`;
exports[`exports/createElement renders different DOM elements 2`] = `<main />`;
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,39 @@

import createElement from '..';
import React from 'react';
import { render, shallow } from 'enzyme';
import { render } from '@testing-library/react';

describe('modules/createElement', () => {
describe('exports/createElement', () => {
test('renders different DOM elements', () => {
let component = render(createElement('span'));
expect(component).toMatchSnapshot();
component = render(createElement('main'));
expect(component).toMatchSnapshot();
let { container } = render(createElement('span'));
expect(container.firstChild).toMatchSnapshot();
({ container } = render(createElement('main')));
expect(container.firstChild).toMatchSnapshot();
});

describe('prop "accessibilityRole"', () => {
test('and string component type', () => {
const component = shallow(createElement('span', { accessibilityRole: 'link' }));
expect(component.find('a').length).toBe(1);
test('string component type', () => {
const { container } = render(createElement('span', { accessibilityRole: 'link' }));
expect(container.firstChild.nodeName).toBe('A');
});

test('and function component type', () => {
test('function component type', () => {
const Custom = () => <div />;
const component = shallow(createElement(Custom, { accessibilityRole: 'link' }));
expect(component.find('div').length).toBe(1);
const { container } = render(createElement(Custom, { accessibilityRole: 'link' }));
expect(container.firstChild.nodeName).toBe('DIV');
});

const testRole = ({ accessibilityRole, disabled }) => {
[{ key: 'Enter' }, { key: ' ' }].forEach(({ key }) => {
test(`"onClick" is ${disabled ? 'not ' : ''}called when "${key}" key is pressed`, () => {
const onClick = jest.fn();
const component = shallow(
const { container } = render(
createElement('span', { accessibilityRole, disabled, onClick })
);
component.find('span').simulate('keyPress', {
isDefaultPrevented() {},
nativeEvent: {},
preventDefault() {},
key
});
const event = document.createEvent('CustomEvent');
event.initCustomEvent('keydown', true, true);
event.key = key;
container.firstChild.dispatchEvent(event);
expect(onClick).toHaveBeenCalledTimes(disabled ? 0 : 1);
});
});
Expand Down
1 change: 0 additions & 1 deletion scripts/jest/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ module.exports = {
roots: ['<rootDir>/packages'],
setupFiles: ['jest-canvas-mock', require.resolve('./setupFiles.js')],
setupFilesAfterEnv: [require.resolve('./setupFramework.js')],
snapshotSerializers: ['enzyme-to-json/serializer'],
testEnvironment: 'jsdom',
timers: 'fake'
};
9 changes: 0 additions & 9 deletions scripts/jest/setupFramework.js
Original file line number Diff line number Diff line change
@@ -1,10 +1 @@
/* eslint-env jasmine, jest */

import Adapter from 'enzyme-adapter-react-16';
import Enzyme from 'enzyme';
import serializer from './serializer';

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

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

0 comments on commit 7e724b2

Please sign in to comment.