mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
* Add missing object-assign dep to create-react-class * Remove unnecessary inlines and irrelevant tests in createFragment * Uninline shallowEqual in shallowCompare * Uninline invariant in update * Uninline invariant/warning and remove unreachable code in react-linked-input * Envify and collapse createClass UMD * Envify and collapse createFragment * ReactLink doesn't really need PropTypes dep It is unnecessary because it is not explicitly exposed and was never public API. * Rebuild, envify and collapse LinkedStateMixin UMD * Collapse PureRenderMixin UMD * Rebuild shallowCompare * Envify and collapse update UMD * Remove unused prop-types dep from linked-input * Fix change handling in LinkedInput * Compile LinkedInput to ES5 * Rebuild, collapse, and fix LinkedInput UMD * Add full README for react-addons-create-fragment * Mention compat version of transition-group so we can delete those docs * README for react-addons-linked-state-mixin * More docs * Fix devDeps for createClass * docs
88 lines
2.5 KiB
JavaScript
88 lines
2.5 KiB
JavaScript
/**
|
|
* Copyright 2015-present, Facebook, Inc.
|
|
* All rights reserved.
|
|
*
|
|
* This source code is licensed under the BSD-style license found in the
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
|
*
|
|
* @emails react-core
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
var React;
|
|
var ReactDOM;
|
|
var createReactFragment;
|
|
|
|
// For testing DOM Fiber.
|
|
global.requestAnimationFrame = function(callback) {
|
|
setTimeout(callback);
|
|
};
|
|
|
|
global.requestIdleCallback = function(callback) {
|
|
setTimeout(() => {
|
|
callback({ timeRemaining() { return Infinity; } });
|
|
});
|
|
};
|
|
|
|
const expectDev = function expectDev(actual) {
|
|
const expectation = expect(actual);
|
|
if (global.__suppressDevFailures) {
|
|
Object.keys(expectation).forEach((name) => {
|
|
wrapDevMatcher(expectation, name);
|
|
wrapDevMatcher(expectation.not, name);
|
|
});
|
|
}
|
|
return expectation;
|
|
};
|
|
|
|
describe('createReactFragment', () => {
|
|
beforeEach(() => {
|
|
jest.resetModules()
|
|
|
|
React = require('react');
|
|
ReactDOM = require('react-dom');
|
|
createReactFragment = require('./index');
|
|
});
|
|
|
|
it('warns for numeric keys on objects as children', () => {
|
|
spyOn(console, 'error');
|
|
|
|
createReactFragment({1: React.createElement('span'), 2: React.createElement('span')});
|
|
|
|
expectDev(console.error.calls.count()).toBe(1);
|
|
expectDev(console.error.calls.argsFor(0)[0]).toContain(
|
|
'Child objects should have non-numeric keys so ordering is preserved.',
|
|
);
|
|
});
|
|
|
|
it('should warn if passing null to createFragment', () => {
|
|
spyOn(console, 'error');
|
|
createReactFragment(null);
|
|
expectDev(console.error.calls.count()).toBe(1);
|
|
expectDev(console.error.calls.argsFor(0)[0]).toContain(
|
|
'React.addons.createFragment only accepts a single object.',
|
|
);
|
|
});
|
|
|
|
it('should warn if passing an array to createFragment', () => {
|
|
spyOn(console, 'error');
|
|
createReactFragment([]);
|
|
expectDev(console.error.calls.count()).toBe(1);
|
|
expectDev(console.error.calls.argsFor(0)[0]).toContain(
|
|
'React.addons.createFragment only accepts a single object.',
|
|
);
|
|
});
|
|
|
|
it('should warn if passing a ReactElement to createFragment', () => {
|
|
spyOn(console, 'error');
|
|
createReactFragment(React.createElement('div'));
|
|
expectDev(console.error.calls.count()).toBe(1);
|
|
expectDev(console.error.calls.argsFor(0)[0]).toContain(
|
|
'React.addons.createFragment does not accept a ReactElement without a ' +
|
|
'wrapper object.',
|
|
);
|
|
});
|
|
});
|