Skip to content

Commit

Permalink
Merge pull request #7 from dabapps/remove-instanceof-check
Browse files Browse the repository at this point in the history
Remove instanceof check
  • Loading branch information
JakeSidSmith authored Jan 27, 2020
2 parents a3501b9 + 357c7be commit fbbff5c
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@dabapps/react-shallow-renderer",
"version": "2.0.0",
"version": "2.0.1",
"description": "A shallow renderer for React components",
"main": "dist/index.js",
"scripts": {
Expand Down
5 changes: 1 addition & 4 deletions src/guards.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import * as React from 'react';

import {
contextSymbol,
elementSymbol,
Expand Down Expand Up @@ -37,8 +35,7 @@ export function isClass(node: ReactAnyNode): node is ReactClassNode {
return (
node.$$typeof === elementSymbol &&
typeof node.type === 'function' &&
(node.type instanceof React.Component ||
(node.type.prototype && 'render' in node.type.prototype) ||
((node.type.prototype && 'render' in node.type.prototype) ||
MATCHES_CLASS.test(Object.toString.call(node.type)))
);
}
Expand Down
22 changes: 22 additions & 0 deletions tests/to-json/component-class.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -199,5 +199,27 @@ describe('ReactShallowRenderer', () => {
_store: {},
});
});

it("renders a component that is class-like, but doesn't inherit from component", () => {
function ClassLike() {
return null;
}

ClassLike.prototype.render = () => <p>Here's the bit we care about!</p>;

const renderer = new ReactShallowRenderer(<ClassLike />);

expect(renderer.toJSON()).toEqual({
$$typeof: elementSymbol,
type: 'p',
key: null,
ref: null,
props: {
children: ["Here's the bit we care about!"],
},
_owner: null,
_store: {},
});
});
});
});

0 comments on commit fbbff5c

Please sign in to comment.