diff --git a/package-lock.json b/package-lock.json index 9335806..af1f17c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "@dabapps/react-shallow-renderer", - "version": "2.0.0", + "version": "2.0.1", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 0ac0550..6272a3d 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/src/guards.ts b/src/guards.ts index af71c36..e46ea37 100644 --- a/src/guards.ts +++ b/src/guards.ts @@ -1,5 +1,3 @@ -import * as React from 'react'; - import { contextSymbol, elementSymbol, @@ -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))) ); } diff --git a/tests/to-json/component-class.tsx b/tests/to-json/component-class.tsx index 1fd83e0..0d0d160 100644 --- a/tests/to-json/component-class.tsx +++ b/tests/to-json/component-class.tsx @@ -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 = () =>
Here's the bit we care about!
; + + const renderer = new ReactShallowRenderer(