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

spread preact-compat Component prototype onto element #21

Closed
wants to merge 3 commits into from
Closed
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
3 changes: 1 addition & 2 deletions __tests__/ShallowWrapper.spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { h } from 'preact';
import { Component } from 'preact-compat';
import { Component, h } from 'preact';
import PropTypes from 'proptypes';
import chai from 'chai';
import sinon from 'sinon';
Expand Down
10 changes: 10 additions & 0 deletions src/PreactAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import renderToString from 'preact-render-to-string';
import ShallowRenderer from 'react-test-renderer/shallow';
import values from 'object.values';
import { EnzymeAdapter } from 'enzyme';
import { Component } from 'preact-compat';
import {
elementToTree,
mapNativeEventNames,
Expand Down Expand Up @@ -122,6 +123,9 @@ export class PreactAdapter extends EnzymeAdapter {
isDOM = true;
} else {
isDOM = false;
if (el.type.prototype.render) {
Object.assign(el.type.prototype, Component.prototype);
}
return withSetStateAllowed(() => renderer.render(el, context));
}
},
Expand All @@ -133,6 +137,12 @@ export class PreactAdapter extends EnzymeAdapter {
return elementToTree(cachedNode);
}
const output = renderer.getRenderOutput();
if (
(output && !output.attributes.children) &&
(output.children && output.children.length)
) {
output.attributes.children = output.children;
}
return {
nodeType: renderer._instance ? 'class' : 'function',
type: cachedNode.nodeName,
Expand Down