diff --git a/packages-internal/test-utils/src/until.js b/packages-internal/test-utils/src/until.js deleted file mode 100644 index aab33f8085bf51..00000000000000 --- a/packages-internal/test-utils/src/until.js +++ /dev/null @@ -1,28 +0,0 @@ -function shallowRecursively(wrapper, selector, { context, ...other }) { - if (wrapper.isEmptyRender() || typeof wrapper.getElement().type === 'string') { - return wrapper; - } - - let newContext = context; - - const instance = wrapper.root().instance(); - // The instance can be null with a stateless functional component and react >= 16. - if (instance && instance.getChildContext) { - newContext = { - ...context, - ...instance.getChildContext(), - }; - } - - const nextWrapper = wrapper.shallow({ context: newContext, ...other }); - - if (selector && wrapper.is(selector)) { - return nextWrapper; - } - - return shallowRecursively(nextWrapper, selector, { context: newContext }); -} - -export default function until(selector, options = {}) { - return this.single('until', () => shallowRecursively(this, selector, options)); -} diff --git a/packages-internal/test-utils/src/until.test.js b/packages-internal/test-utils/src/until.test.js deleted file mode 100644 index ee9edc05292249..00000000000000 --- a/packages-internal/test-utils/src/until.test.js +++ /dev/null @@ -1,120 +0,0 @@ -import * as React from 'react'; -import { expect } from 'chai'; -import PropTypes from 'prop-types'; -import { shallow } from 'enzyme'; -import until from './until'; - -function Div() { - return
; -} -const hoc = (Component) => - function Wrapper() { - return ; - }; - -describe('until', () => { - it('shallow renders the current wrapper one level deep', () => { - const EnhancedDiv = hoc(Div); - const wrapper = until.call(shallow(), 'Div'); - expect(wrapper.contains(
)).to.equal(true); - }); - - it('shallow renders the current wrapper several levels deep', () => { - const EnhancedDiv = hoc(hoc(hoc(Div))); - const wrapper = until.call(shallow(), 'Div'); - expect(wrapper.contains(
)).to.equal(true); - }); - - it('stops shallow rendering when the wrapper is empty', () => { - const nullHoc = () => () => null; - const EnhancedDiv = nullHoc(); - const wrapper = until.call(shallow(), 'Div'); - expect(wrapper.html()).to.equal(null); - }); - - it('shallow renders as much as possible when no selector is provided', () => { - const EnhancedDiv = hoc(hoc(Div)); - const wrapper = until.call(shallow()); - expect(wrapper.contains(
)).to.equal(true); - }); - - it('shallow renders the current wrapper even if the selector never matches', () => { - const EnhancedDiv = hoc(Div); - const wrapper = until.call(shallow(), 'NotDiv'); - expect(wrapper.contains(
)).to.equal(true); - }); - - it('stops shallow rendering when it encounters a HTML element', () => { - const wrapper = until.call( - shallow( -
-
-
, - ), - 'Div', - ); - expect( - wrapper.contains( -
-
-
, - ), - ).to.equal(true); - }); - - it('throws when until called on an empty wrapper', () => { - expect(() => { - until.call(shallow(
).find('Foo'), 'div'); - }).to.throw(Error); - }); - - it('shallow renders non-root wrappers', () => { - function Container() { - return ( -
-
-
- ); - } - const wrapper = until.call(shallow().find(Div)); - expect(wrapper.contains(
)).to.equal(true); - }); - - // eslint-disable-next-line react/prefer-stateless-function - class Foo extends React.Component { - render() { - return
; - } - } - - Foo.contextTypes = { - quux: PropTypes.bool.isRequired, - }; - - it('context propagation passes down context from the root component', () => { - const EnhancedFoo = hoc(Foo); - const options = { context: { quux: true } }; - const wrapper = until.call(shallow(, options), 'Foo', options); - expect(wrapper.context('quux')).to.equal(true); - expect(wrapper.contains(
)).to.equal(true); - }); - - class Bar extends React.Component { - static childContextTypes = { quux: PropTypes.bool }; - - getChildContext() { - return { quux: true }; - } - - render() { - return ; - } - } - - it('context propagation passes down context from an intermediary component', () => { - const EnhancedBar = hoc(Bar); - const wrapper = until.call(shallow(), 'Foo'); - expect(wrapper.context('quux')).to.equal(true); - expect(wrapper.contains(
)).to.equal(true); - }); -});