From 1212ca803225ad89efc10da430ac8fbf01f00bc3 Mon Sep 17 00:00:00 2001 From: Jake 'Sid' Smith Date: Mon, 27 Jan 2020 12:15:26 +0000 Subject: [PATCH 1/3] Remove check for node type being instanceof component --- src/guards.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) 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))) ); } From 01a8401a706c3958e308cda678576f9102cb35b6 Mon Sep 17 00:00:00 2001 From: Jake 'Sid' Smith Date: Mon, 27 Jan 2020 13:44:18 +0000 Subject: [PATCH 2/3] Test class-like components rendering --- tests/to-json/component-class.tsx | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) 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(); + + expect(renderer.toJSON()).toEqual({ + $$typeof: elementSymbol, + type: 'p', + key: null, + ref: null, + props: { + children: ["Here's the bit we care about!"], + }, + _owner: null, + _store: {}, + }); + }); }); }); From 357c7bedc2464cb614220d4a999b455c44593ce8 Mon Sep 17 00:00:00 2001 From: Jake 'Sid' Smith Date: Mon, 27 Jan 2020 13:48:56 +0000 Subject: [PATCH 3/3] 2.0.1 --- package-lock.json | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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": {