Skip to content

Commit aca9c8a

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

File tree

2 files changed

+68
-26
lines changed

2 files changed

+68
-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: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
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+
15+
let ReactFeatureFlags = require('shared/ReactFeatureFlags');
16+
17+
// NOTE: We're explicitly not using JSX here. This is intended to test
18+
// a new React.jsx api which does not have a JSX transformer yet.
19+
// A lot of these tests are pulled from ReactElement-test because
20+
// this api is meant to be backwards compatible.
21+
describe('ReactElementJSXNewWarnings', () => {
22+
let originalSymbol;
23+
24+
beforeEach(() => {
25+
jest.resetModules();
26+
27+
// Delete the native Symbol if we have one to ensure we test the
28+
// unpolyfilled environment.
29+
originalSymbol = global.Symbol;
30+
global.Symbol = undefined;
31+
32+
ReactFeatureFlags = require('shared/ReactFeatureFlags');
33+
ReactFeatureFlags.warnAboutSpreadingKeyToJSX = true;
34+
35+
React = require('react');
36+
ReactDOM = require('react-dom');
37+
});
38+
39+
afterEach(() => {
40+
global.Symbol = originalSymbol;
41+
});
42+
43+
if (!__EXPERIMENTAL__) {
44+
it("empty test so Jest doesn't complain", () => {});
45+
return;
46+
}
47+
48+
it('should warn when keys are passed as part of props', () => {
49+
const container = document.createElement('div');
50+
class Child extends React.Component {
51+
render() {
52+
return React.jsx('div', {});
53+
}
54+
}
55+
class Parent extends React.Component {
56+
render() {
57+
return React.jsx('div', {
58+
children: [React.jsx(Child, {key: '0'})],
59+
});
60+
}
61+
}
62+
expect(() => ReactDOM.render(React.jsx(Parent, {}), container)).toErrorDev(
63+
'Warning: React.jsx: Spreading a key to JSX is a deprecated pattern. ' +
64+
'Explicitly pass a key after spreading props in your JSX call. ' +
65+
'E.g. <Child {...props} key={key} />',
66+
);
67+
});
68+
});

0 commit comments

Comments
 (0)