Skip to content

Commit

Permalink
Move test to ReactContextValidator
Browse files Browse the repository at this point in the history
  • Loading branch information
eps1lon committed Mar 4, 2020
1 parent 0728d1f commit 3968e0b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 45 deletions.
45 changes: 0 additions & 45 deletions packages/react/src/__tests__/ReactContext-test.js

This file was deleted.

24 changes: 24 additions & 0 deletions packages/react/src/__tests__/ReactContextValidator-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
let PropTypes;
let React;
let ReactDOM;
let ReactDOMServer;
let ReactTestUtils;

describe('ReactContextValidator', () => {
Expand All @@ -27,6 +28,7 @@ describe('ReactContextValidator', () => {
PropTypes = require('prop-types');
React = require('react');
ReactDOM = require('react-dom');
ReactDOMServer = require('react-dom/server');
ReactTestUtils = require('react-dom/test-utils');
});

Expand Down Expand Up @@ -671,4 +673,26 @@ describe('ReactContextValidator', () => {
'Warning: ComponentB: Function components do not support contextType.',
);
});

it('should honor a displayName if set on the context type', () => {
const Context = React.createContext(null);
Context.displayName = 'MyContextType';
function Validator() {
return null;
}
Validator.propTypes = {dontPassToSeeErrorStack: PropTypes.bool.isRequired};

expect(() => {
ReactDOMServer.renderToStaticMarkup(
<Context.Provider>
<Context.Consumer>{() => <Validator />}</Context.Consumer>
</Context.Provider>,
);
}).toErrorDev(
'Warning: Failed prop type: The prop `dontPassToSeeErrorStack` is marked as required in `Validator`, but its value is `undefined`.\n' +
' in Validator (at **)\n' +
' in MyContextType.Consumer (at **)\n' +
' in MyContextType.Provider (at **)',
);
});
});

0 comments on commit 3968e0b

Please sign in to comment.