Skip to content

Commit

Permalink
Merge pull request #12 from plusnew/hostNodes
Browse files Browse the repository at this point in the history
[commonWrapper] add hosteNodes function
  • Loading branch information
plusgut committed May 20, 2019
2 parents 7818111 + 4a4870f commit 49974c0
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "enzyme-adapter-plusnew",
"version": "0.6.44",
"version": "0.6.45",
"description": "adapter for enzyme testsuite to the plusnew framework",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
4 changes: 4 additions & 0 deletions src/wrapper/PlusnewCommonWrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ abstract class PlusnewCommonWrapper {
return this.wrapper.hasClass.apply(this.wrapper, arguments);
}

public hostNodes(): this {
return new this.WrapperClass(this.wrapper.hostNodes.apply(this.wrapper, arguments));
}

public html(): string {
return this.wrapper.html.apply(this.wrapper, arguments);
}
Expand Down
29 changes: 27 additions & 2 deletions test/mount_shallow.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import PlusnewCommonWrapper from 'wrapper/PlusnewCommonWrapper';
import { configure } from 'enzyme';
import plusnew, { component, store, Props } from 'plusnew';

interface common {
interface Common {
(element: plusnew.JSX.Element): PlusnewCommonWrapper;
}

function getMountFunction(callback: (mountWrapper: common) => void) {
function getMountFunction(callback: (mountWrapper: Common) => void) {
callback(mount as any);
callback(shallow as any);
}
Expand Down Expand Up @@ -428,6 +428,31 @@ describe('testing both renderers with:', () => {
});
});

describe('hostNodes()', () => {
it('basic test', () => {
getMountFunction((mount) => {
const MyComponent = component(
'MyComponent',
(_Props: Props<{ className: string }>) => false,
);

const MainComponent = component(
'Component',
() =>
<div>
<MyComponent className="foo" />
<span className="foo" />
</div>,
);

const wrapper = mount(<MainComponent />);

const twoNodes = wrapper.find('.foo');
expect(twoNodes.hostNodes().length).toBe(1);
});
});
});

describe('html()', () => {
it('basic test', () => {
getMountFunction((mount) => {
Expand Down

0 comments on commit 49974c0

Please sign in to comment.