Skip to content

Commit b1e3b28

Browse files
committed
Run ReactElementJSX-test against bundles
1 parent 885ed46 commit b1e3b28

File tree

2 files changed

+70
-26
lines changed

2 files changed

+70
-26
lines changed

packages/react/src/__tests__/ReactElementJSX-test.internal.js renamed to packages/react/src/__tests__/ReactElementJSX-test.js

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ let React;
1313
let ReactDOM;
1414
let ReactTestUtils;
1515

16-
let ReactFeatureFlags = require('shared/ReactFeatureFlags');
17-
1816
// NOTE: We're explicitly not using JSX here. This is intended to test
1917
// a new React.jsx api which does not have a JSX transformer yet.
2018
// A lot of these tests are pulled from ReactElement-test because
@@ -30,9 +28,6 @@ describe('ReactElement.jsx', () => {
3028
originalSymbol = global.Symbol;
3129
global.Symbol = undefined;
3230

33-
ReactFeatureFlags = require('shared/ReactFeatureFlags');
34-
ReactFeatureFlags.warnAboutSpreadingKeyToJSX = true;
35-
3631
React = require('react');
3732
ReactDOM = require('react-dom');
3833
ReactTestUtils = require('react-dom/test-utils');
@@ -356,27 +351,6 @@ describe('ReactElement.jsx', () => {
356351
);
357352
});
358353

359-
it('should warn when keys are passed as part of props', () => {
360-
const container = document.createElement('div');
361-
class Child extends React.Component {
362-
render() {
363-
return React.jsx('div', {});
364-
}
365-
}
366-
class Parent extends React.Component {
367-
render() {
368-
return React.jsx('div', {
369-
children: [React.jsx(Child, {key: '0'})],
370-
});
371-
}
372-
}
373-
expect(() => ReactDOM.render(React.jsx(Parent, {}), container)).toErrorDev(
374-
'Warning: React.jsx: Spreading a key to JSX is a deprecated pattern. ' +
375-
'Explicitly pass a key after spreading props in your JSX call. ' +
376-
'E.g. <Child {...props} key={key} />',
377-
);
378-
});
379-
380354
it('should not warn when unkeyed children are passed to jsxs', () => {
381355
const container = document.createElement('div');
382356
class Child extends React.Component {
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @emails react-core
8+
*/
9+
10+
'use strict';
11+
12+
let React;
13+
let ReactDOM;
14+
let ReactTestUtils;
15+
16+
let ReactFeatureFlags = require('shared/ReactFeatureFlags');
17+
18+
// NOTE: We're explicitly not using JSX here. This is intended to test
19+
// a new React.jsx api which does not have a JSX transformer yet.
20+
// A lot of these tests are pulled from ReactElement-test because
21+
// this api is meant to be backwards compatible.
22+
describe('ReactElementJSXNewWarnings', () => {
23+
let originalSymbol;
24+
25+
beforeEach(() => {
26+
jest.resetModules();
27+
28+
// Delete the native Symbol if we have one to ensure we test the
29+
// unpolyfilled environment.
30+
originalSymbol = global.Symbol;
31+
global.Symbol = undefined;
32+
33+
ReactFeatureFlags = require('shared/ReactFeatureFlags');
34+
ReactFeatureFlags.warnAboutSpreadingKeyToJSX = true;
35+
36+
React = require('react');
37+
ReactDOM = require('react-dom');
38+
ReactTestUtils = require('react-dom/test-utils');
39+
});
40+
41+
afterEach(() => {
42+
global.Symbol = originalSymbol;
43+
});
44+
45+
if (!__EXPERIMENTAL__) {
46+
it("empty test so Jest doesn't complain", () => {});
47+
return;
48+
}
49+
50+
it('should warn when keys are passed as part of props', () => {
51+
const container = document.createElement('div');
52+
class Child extends React.Component {
53+
render() {
54+
return React.jsx('div', {});
55+
}
56+
}
57+
class Parent extends React.Component {
58+
render() {
59+
return React.jsx('div', {
60+
children: [React.jsx(Child, {key: '0'})],
61+
});
62+
}
63+
}
64+
expect(() => ReactDOM.render(React.jsx(Parent, {}), container)).toErrorDev(
65+
'Warning: React.jsx: Spreading a key to JSX is a deprecated pattern. ' +
66+
'Explicitly pass a key after spreading props in your JSX call. ' +
67+
'E.g. <Child {...props} key={key} />',
68+
);
69+
});
70+
});

0 commit comments

Comments
 (0)