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

Fix check of node type #145

Merged
merged 2 commits into from
Aug 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"lodash": "^4.17.12"
},
"peerDependencies": {
"enzyme": "^3.4.0"
"enzyme": "^3.10.0"
},
"devDependencies": {
"babel-cli": "^6.26.0",
Expand All @@ -54,8 +54,8 @@
"babel-plugin-transform-react-jsx": "^6.24.1",
"babel-preset-env": "^1.6.0",
"codecov": "^2.3.0",
"enzyme": "^3.7.0",
"enzyme-adapter-react-16": "^1.7.0",
"enzyme": "^3.10.0",
"enzyme-adapter-react-16": "^1.14.0",
"eslint": "^4.8.0",
"eslint-config-prettier": "^2.6.0",
"eslint-config-standard": "^10.2.1",
Expand Down
10 changes: 5 additions & 5 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,19 @@ export const applyMap = (json, options) => {
};

export const extractTypeName = node => {
const name = typeName(node);
const type = node.type.$$typeof;

if (name.$$typeof === Symbol.for('react.lazy')) {
if (type === Symbol.for('react.lazy')) {
return 'React.Lazy';
}

if (name.$$typeof === Symbol.for('react.memo')) {
if (type === Symbol.for('react.memo')) {
return 'React.Memo';
}

if (name === Symbol.for('react.suspense')) {
if (node.type === Symbol.for('react.suspense')) {
return 'React.Suspense';
}

return name;
return typeName(node);
};
14 changes: 12 additions & 2 deletions tests/utils.test.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
/* eslint-env jest */

import React from 'react';
// import React from 'react';
import React, {memo, lazy, Suspense} from 'react';
import Enzyme, {shallow, mount, render} from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';
import {isEnzymeWrapper} from '../src/utils';
import {isEnzymeWrapper, extractTypeName} from '../src/utils';

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

const Lazy = lazy(() => Promise.resolve(<div>lazy div</div>));
const Memo = memo(() => <div>memoized div</div>);

it('returns true whenever it is an enzyme wrapper', () => {
expect(isEnzymeWrapper(shallow(<div />))).toBe(true);
expect(isEnzymeWrapper(mount(<div />))).toBe(true);
Expand All @@ -18,3 +22,9 @@ it('returns false whenever it is an enzyme wrapper', () => {
expect(isEnzymeWrapper('test')).toBe(false);
expect(isEnzymeWrapper(<div />)).toBe(false);
});

it('returns correct node type', () => {
expect(extractTypeName(<Lazy />)).toBe('React.Lazy');
expect(extractTypeName(<Memo />)).toBe('React.Memo');
expect(extractTypeName(<Suspense />)).toBe('React.Suspense');
})
Loading