Skip to content

Commit

Permalink
[enzyme-adapter-utils] [refactor] remove unused code from createMount…
Browse files Browse the repository at this point in the history
…Wrapper; 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.
  • Loading branch information
ljharb committed Sep 23, 2019
1 parent 5d343e2 commit 66ff0d4
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 23 deletions.
23 changes: 0 additions & 23 deletions packages/enzyme-adapter-utils/src/createMountWrapper.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ export default function createMountWrapper(node, options = {}) {
constructor(...args) {
super(...args);
const { props, wrappingComponentProps, context } = this.props;
this.rootFinderInstance = null;
this.state = {
mount: true,
props,
Expand All @@ -68,28 +67,6 @@ export default function createMountWrapper(node, options = {}) {
this.setState({ wrappingComponentProps: props }, callback);
}

getInstance() {
const component = this._reactInternalInstance._renderedComponent;
const inst = component.getPublicInstance();
if (inst === null) {
return component._instance;
}
return inst;
}

getWrappedComponent() {
const component = this._reactInternalInstance._renderedComponent;
const inst = component.getPublicInstance();
if (inst === null) {
return component._instance;
}
return inst;
}

setChildContext(context) {
return new Promise((resolve) => this.setState({ context }, resolve));
}

render() {
const { Component } = this.props;
const { mount, props, wrappingComponentProps } = this.state;
Expand Down
27 changes: 27 additions & 0 deletions packages/enzyme-test-suite/test/adapter-utils-spec.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import React from 'react';
import { expect } from 'chai';
import sinon from 'sinon-sandbox';
import PropTypes from 'prop-types';
import { shallow } from 'enzyme';
import {
displayNameOfNode,
ensureKeyOrUndefined,
Expand All @@ -14,6 +16,7 @@ import {
getWrappingComponentMountRenderer,
fakeDynamicImport,
assertDomAvailable,
createMountWrapper,
} from 'enzyme-adapter-utils';
import wrap from 'mocha-wrap';

Expand Down Expand Up @@ -483,4 +486,28 @@ describe('enzyme-adapter-utils', () => {
});
});
});

describe('createMountWrapper', () => {
class Foo extends React.Component {
render() { return <div>{this.context.foo}</div>; }
}
Foo.contextTypes = {
foo: PropTypes.string,
};

it('returns a component', () => {
const node = <Foo />;
const Wrapper = createMountWrapper(node);
expect(React.isValidElement(<Wrapper />)).to.equal(true);
});

it('returns the wrapped component’s instance', () => {
const node = <Foo />;
const Wrapper = createMountWrapper(node);
const wrapper = shallow(<Wrapper />);
expect(wrapper.instance()).to.be.instanceOf(Wrapper);
});

it('uses the passed `wrappingComponent`', () => {});
});
});

0 comments on commit 66ff0d4

Please sign in to comment.