Skip to content

Commit 66ff0d4

Browse files
committed
[enzyme-adapter-utils] [refactor] remove unused code from createMountWrapper; add tests
Technically this could be considered a breaking change since it’s a `class` and these are public methods on it. *However*, since nobody should be depending on this package directly, and since enzyme itself doesn’t appear to use it, I’m going to consider it a patch. In the event that it is a breaking change for someone, I’ll add back the methods, ideally as no-ops.
1 parent 5d343e2 commit 66ff0d4

File tree

2 files changed

+27
-23
lines changed

2 files changed

+27
-23
lines changed

packages/enzyme-adapter-utils/src/createMountWrapper.jsx

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ export default function createMountWrapper(node, options = {}) {
4848
constructor(...args) {
4949
super(...args);
5050
const { props, wrappingComponentProps, context } = this.props;
51-
this.rootFinderInstance = null;
5251
this.state = {
5352
mount: true,
5453
props,
@@ -68,28 +67,6 @@ export default function createMountWrapper(node, options = {}) {
6867
this.setState({ wrappingComponentProps: props }, callback);
6968
}
7069

71-
getInstance() {
72-
const component = this._reactInternalInstance._renderedComponent;
73-
const inst = component.getPublicInstance();
74-
if (inst === null) {
75-
return component._instance;
76-
}
77-
return inst;
78-
}
79-
80-
getWrappedComponent() {
81-
const component = this._reactInternalInstance._renderedComponent;
82-
const inst = component.getPublicInstance();
83-
if (inst === null) {
84-
return component._instance;
85-
}
86-
return inst;
87-
}
88-
89-
setChildContext(context) {
90-
return new Promise((resolve) => this.setState({ context }, resolve));
91-
}
92-
9370
render() {
9471
const { Component } = this.props;
9572
const { mount, props, wrappingComponentProps } = this.state;

packages/enzyme-test-suite/test/adapter-utils-spec.jsx

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import React from 'react';
22
import { expect } from 'chai';
33
import sinon from 'sinon-sandbox';
4+
import PropTypes from 'prop-types';
5+
import { shallow } from 'enzyme';
46
import {
57
displayNameOfNode,
68
ensureKeyOrUndefined,
@@ -14,6 +16,7 @@ import {
1416
getWrappingComponentMountRenderer,
1517
fakeDynamicImport,
1618
assertDomAvailable,
19+
createMountWrapper,
1720
} from 'enzyme-adapter-utils';
1821
import wrap from 'mocha-wrap';
1922

@@ -483,4 +486,28 @@ describe('enzyme-adapter-utils', () => {
483486
});
484487
});
485488
});
489+
490+
describe('createMountWrapper', () => {
491+
class Foo extends React.Component {
492+
render() { return <div>{this.context.foo}</div>; }
493+
}
494+
Foo.contextTypes = {
495+
foo: PropTypes.string,
496+
};
497+
498+
it('returns a component', () => {
499+
const node = <Foo />;
500+
const Wrapper = createMountWrapper(node);
501+
expect(React.isValidElement(<Wrapper />)).to.equal(true);
502+
});
503+
504+
it('returns the wrapped component’s instance', () => {
505+
const node = <Foo />;
506+
const Wrapper = createMountWrapper(node);
507+
const wrapper = shallow(<Wrapper />);
508+
expect(wrapper.instance()).to.be.instanceOf(Wrapper);
509+
});
510+
511+
it('uses the passed `wrappingComponent`', () => {});
512+
});
486513
});

0 commit comments

Comments
 (0)