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

Use public API in tests wherever possible #9954

Merged
merged 2 commits into from
Jun 13, 2017
Merged
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
2 changes: 1 addition & 1 deletion src/isomorphic/children/__tests__/ReactChildren-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe('ReactChildren', () => {
beforeEach(() => {
jest.resetModules();
React = require('react');
ReactTestUtils = require('ReactTestUtils');
ReactTestUtils = require('react-dom/test-utils');
});

it('should support identity for simple', () => {
Expand Down
16 changes: 7 additions & 9 deletions src/isomorphic/children/__tests__/onlyChild-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,15 @@

describe('onlyChild', () => {
var React;
var onlyChild;
var WrapComponent;

beforeEach(() => {
React = require('react');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gaearon How does this require work right now? I couldn't find any jest mocks for 'react'

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check src/node_modules/react

onlyChild = require('onlyChild');
WrapComponent = class extends React.Component {
render() {
return (
<div>
{onlyChild(this.props.children, this.props.mapFn, this)}
{React.Children.only(this.props.children, this.props.mapFn, this)}
</div>
);
}
Expand All @@ -38,7 +36,7 @@ describe('onlyChild', () => {
<span />
</WrapComponent>
);
onlyChild(instance.props.children);
React.Children.only(instance.props.children);
}).toThrow();
});

Expand All @@ -49,7 +47,7 @@ describe('onlyChild', () => {
{null}
</WrapComponent>
);
onlyChild(instance.props.children);
React.Children.only(instance.props.children);
}).toThrow();

expect(function() {
Expand All @@ -58,7 +56,7 @@ describe('onlyChild', () => {
{undefined}
</WrapComponent>
);
onlyChild(instance.props.children);
React.Children.only(instance.props.children);
}).toThrow();
});

Expand All @@ -69,7 +67,7 @@ describe('onlyChild', () => {
{[<span key="abc" />]}
</WrapComponent>
);
onlyChild(instance.props.children);
React.Children.only(instance.props.children);
}).toThrow();
});

Expand All @@ -80,7 +78,7 @@ describe('onlyChild', () => {
{<span />}
</WrapComponent>
);
onlyChild(instance.props.children);
React.Children.only(instance.props.children);
}).not.toThrow();
});

Expand All @@ -90,6 +88,6 @@ describe('onlyChild', () => {
<span />
</WrapComponent>
);
expect(onlyChild(instance.props.children)).toEqual(<span />);
expect(React.Children.only(instance.props.children)).toEqual(<span />);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ describe('ReactContextValidator', () => {
PropTypes = require('prop-types');
React = require('react');
ReactDOM = require('react-dom');
ReactTestUtils = require('ReactTestUtils');
ReactTestUtils = require('react-dom/test-utils');
});

// TODO: This behavior creates a runtime dependency on propTypes. We should
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ describe('create-react-class-integration', () => {
PropTypes = require('prop-types');
React = require('react');
ReactDOM = require('react-dom');
ReactTestUtils = require('ReactTestUtils');
ReactTestUtils = require('react-dom/test-utils');
createReactClass = require('create-react-class/factory')(
React.Component,
React.isValidElement,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe('ReactElement', () => {

React = require('react');
ReactDOM = require('react-dom');
ReactTestUtils = require('ReactTestUtils');
ReactTestUtils = require('react-dom/test-utils');
ReactDOMFeatureFlags = require('ReactDOMFeatureFlags');
// NOTE: We're explicitly not using JSX here. This is intended to test
// classic JS without JSX.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe('ReactElementClone', () => {
PropTypes = require('prop-types');
React = require('react');
ReactDOM = require('react-dom');
ReactTestUtils = require('ReactTestUtils');
ReactTestUtils = require('react-dom/test-utils');

// NOTE: We're explicitly not using JSX here. This is intended to test
// classic JS without JSX.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ describe('ReactElementValidator', () => {
PropTypes = require('prop-types');
React = require('react');
ReactDOM = require('react-dom');
ReactTestUtils = require('ReactTestUtils');
ReactTestUtils = require('react-dom/test-utils');
ComponentClass = class extends React.Component {
render() {
return React.createElement('div');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe('ReactJSXElement', () => {

React = require('react');
ReactDOM = require('react-dom');
ReactTestUtils = require('ReactTestUtils');
ReactTestUtils = require('react-dom/test-utils');
Component = class extends React.Component {
render() {
return <div />;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ describe('ReactJSXElementValidator', () => {
PropTypes = require('prop-types');
React = require('react');
ReactDOM = require('react-dom');
ReactTestUtils = require('ReactTestUtils');
ReactTestUtils = require('react-dom/test-utils');

Component = class extends React.Component {
render() {
Expand Down
9 changes: 9 additions & 0 deletions src/node_modules/react-art/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions src/node_modules/react-dom/test-utils.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions src/node_modules/react-native/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions src/node_modules/react-noop-renderer/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions src/node_modules/react-test-renderer/shallow.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/renderers/__tests__/EventPluginHub-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe('EventPluginHub', () => {
beforeEach(() => {
jest.resetModules();
React = require('react');
ReactTestUtils = require('ReactTestUtils');
ReactTestUtils = require('react-dom/test-utils');
});

it('should prevent non-function listeners, at dispatch', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/renderers/__tests__/ReactChildReconciler-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe('ReactChildReconciler', () => {
jest.resetModules();

React = require('react');
ReactTestUtils = require('ReactTestUtils');
ReactTestUtils = require('react-dom/test-utils');
});

function createIterable(array) {
Expand Down
2 changes: 1 addition & 1 deletion src/renderers/__tests__/ReactComponent-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe('ReactComponent', () => {
React = require('react');
ReactDOM = require('react-dom');
ReactDOMFeatureFlags = require('ReactDOMFeatureFlags');
ReactTestUtils = require('ReactTestUtils');
ReactTestUtils = require('react-dom/test-utils');
});

it('should throw on invalid render targets', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/renderers/__tests__/ReactComponentLifeCycle-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ describe('ReactComponentLifeCycle', () => {
jest.resetModules();
React = require('react');
ReactDOM = require('react-dom');
ReactTestUtils = require('ReactTestUtils');
ReactTestUtils = require('react-dom/test-utils');
PropTypes = require('prop-types');
});

Expand Down
5 changes: 3 additions & 2 deletions src/renderers/__tests__/ReactCompositeComponent-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ describe('ReactCompositeComponent', () => {
React = require('react');
ReactDOM = require('react-dom');
ReactDOMServer = require('react-dom/server');
ReactCurrentOwner = require('ReactCurrentOwner');
ReactTestUtils = require('ReactTestUtils');
ReactCurrentOwner = require('react')
.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems fair to me—it's what renderers do too.

ReactTestUtils = require('react-dom/test-utils');
PropTypes = require('prop-types');
shallowEqual = require('fbjs/lib/shallowEqual');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe('ReactCompositeComponentDOMMinimalism', () => {
beforeEach(() => {
React = require('react');
ReactDOM = require('react-dom');
ReactTestUtils = require('ReactTestUtils');
ReactTestUtils = require('react-dom/test-utils');

LowerLevelComposite = class extends React.Component {
render() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe('ReactCompositeComponentNestedState-state', () => {
beforeEach(() => {
React = require('react');
ReactDOM = require('react-dom');
ReactTestUtils = require('ReactTestUtils');
ReactTestUtils = require('react-dom/test-utils');
});

it('should provide up to date values for props', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/renderers/__tests__/ReactEmptyComponent-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe('ReactEmptyComponent', () => {
React = require('react');
ReactDOM = require('react-dom');
ReactDOMFeatureFlags = require('ReactDOMFeatureFlags');
ReactTestUtils = require('ReactTestUtils');
ReactTestUtils = require('react-dom/test-utils');

log = jasmine.createSpy();

Expand Down
2 changes: 1 addition & 1 deletion src/renderers/__tests__/ReactIdentity-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe('ReactIdentity', () => {
jest.resetModules();
React = require('react');
ReactDOM = require('react-dom');
ReactTestUtils = require('ReactTestUtils');
ReactTestUtils = require('react-dom/test-utils');
});

it('should allow key property to express identity', () => {
Expand Down
4 changes: 2 additions & 2 deletions src/renderers/__tests__/ReactMockedComponent-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ var ReactDOMServer;
describe('ReactMockedComponent', () => {
beforeEach(() => {
React = require('react');
ReactTestUtils = require('ReactTestUtils');
ReactDOMServer = require('ReactDOMServer');
ReactTestUtils = require('react-dom/test-utils');
ReactDOMServer = require('react-dom/server');

AutoMockedComponent = jest.genMockFromModule(
'ReactMockedComponentTestComponent',
Expand Down
2 changes: 1 addition & 1 deletion src/renderers/__tests__/ReactMultiChildText-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
var React = require('react');
var ReactDOM = require('react-dom');
var ReactDOMFeatureFlags = require('ReactDOMFeatureFlags');
var ReactTestUtils = require('ReactTestUtils');
var ReactTestUtils = require('react-dom/test-utils');

// Helpers
var testAllPermutations = function(testCases) {
Expand Down
3 changes: 2 additions & 1 deletion src/renderers/__tests__/ReactTreeTraversal-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@
'use strict';

var React = require('react');
// TODO: can we express this test with only public API?
var ReactDOMComponentTree = require('ReactDOMComponentTree');
var ReactTestUtils = require('ReactTestUtils');
var ReactTestUtils = require('react-dom/test-utils');

/**
* Ensure that all callbacks are invoked, passing this unique argument.
Expand Down
2 changes: 1 addition & 1 deletion src/renderers/__tests__/ReactUpdates-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('ReactUpdates', () => {
React = require('react');
ReactDOM = require('react-dom');
ReactDOMFeatureFlags = require('ReactDOMFeatureFlags');
ReactTestUtils = require('ReactTestUtils');
ReactTestUtils = require('react-dom/test-utils');
});

it('should batch state when updating state twice', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/renderers/__tests__/refs-destruction-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe('refs-destruction', () => {

React = require('react');
ReactDOM = require('react-dom');
ReactTestUtils = require('ReactTestUtils');
ReactTestUtils = require('react-dom/test-utils');

TestComponent = class extends React.Component {
render() {
Expand Down
2 changes: 1 addition & 1 deletion src/renderers/__tests__/refs-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

var React = require('react');
var ReactDOMFeatureFlags = require('ReactDOMFeatureFlags');
var ReactTestUtils = require('ReactTestUtils');
var ReactTestUtils = require('react-dom/test-utils');

/**
* Counts clicks and has a renders an item for each click. Each item rendered
Expand Down
4 changes: 2 additions & 2 deletions src/renderers/art/__tests__/ReactART-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

var React = require('react');
var ReactDOM = require('react-dom');
var ReactTestUtils = require('ReactTestUtils');
var ReactTestUtils = require('react-dom/test-utils');

var Group;
var Shape;
Expand All @@ -24,7 +24,7 @@ var TestComponent;

var Missing = {};

var ReactART = require('ReactARTFiber');
var ReactART = require('react-art');
var ARTSVGMode = require('art/modes/svg');
var ARTCurrentMode = require('art/modes/current');

Expand Down
2 changes: 1 addition & 1 deletion src/renderers/dom/fiber/__tests__/ReactDOMFiber-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
var React = require('react');
var ReactDOM = require('react-dom');
var ReactDOMFeatureFlags = require('ReactDOMFeatureFlags');
var ReactTestUtils = require('ReactTestUtils');
var ReactTestUtils = require('react-dom/test-utils');
var PropTypes = require('prop-types');

describe('ReactDOMFiber', () => {
Expand Down
1 change: 1 addition & 0 deletions src/renderers/dom/shared/__tests__/CSSProperty-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ describe('CSSProperty', () => {

beforeEach(() => {
jest.resetModules();
// TODO: can we express this test with only public API?
CSSProperty = require('CSSProperty');
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ describe('DOMPropertyOperations', () => {
var ReactDOMInjection = require('ReactDOMInjection');
ReactDOMInjection.inject();

// TODO: can we express this test with only public API?
DOMPropertyOperations = require('DOMPropertyOperations');
DOMProperty = require('DOMProperty');
ReactDOMComponentTree = require('ReactDOMComponentTree');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,14 @@ describe('ReactBrowserEventEmitter', () => {
jest.resetModules();
LISTENER.mockClear();
EventListener = require('fbjs/lib/EventListener');
// TODO: can we express this test with only public API?
EventPluginHub = require('EventPluginHub');
EventPluginRegistry = require('EventPluginRegistry');
React = require('react');
ReactDOM = require('react-dom');
ReactDOMComponentTree = require('ReactDOMComponentTree');
ReactBrowserEventEmitter = require('ReactBrowserEventEmitter');
ReactTestUtils = require('ReactTestUtils');
ReactTestUtils = require('react-dom/test-utils');
TapEventPlugin = require('TapEventPlugin');

var container = document.createElement('div');
Expand Down
Loading