Skip to content
Merged
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
46 changes: 23 additions & 23 deletions src/core/__tests__/ReactElement-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,21 @@ var ReactElement;
var ReactTestUtils;

describe('ReactElement', function() {
var ComponentFactory;
var ComponentClass;

beforeEach(function() {
require('mock-modules').dumpCache();

React = require('React');
ReactElement = require('ReactElement');
ReactTestUtils = require('ReactTestUtils');
ComponentFactory = React.createClass({
ComponentClass = React.createClass({
render: function() { return <div />; }
});
ComponentClass = ComponentFactory;
});

it('returns a complete element according to spec', function() {
var element = React.createFactory(ComponentFactory)();
var element = React.createFactory(ComponentClass)();
expect(element.type).toBe(ComponentClass);
expect(element.key).toBe(null);
expect(element.ref).toBe(null);
Expand All @@ -46,20 +46,20 @@ describe('ReactElement', function() {
});

it('returns an immutable element', function() {
var element = React.createFactory(ComponentFactory)();
var element = React.createFactory(ComponentClass)();
expect(() => element.type = 'div').toThrow();
});

it('does not reuse the original config object', function() {
var config = { foo: 1 };
var element = React.createFactory(ComponentFactory)(config);
var element = React.createFactory(ComponentClass)(config);
expect(element.props.foo).toBe(1);
config.foo = 2;
expect(element.props.foo).toBe(1);
});

it('extracts key and ref from the config', function() {
var element = React.createFactory(ComponentFactory)({
var element = React.createFactory(ComponentClass)({
key: '12',
ref: '34',
foo: '56'
Expand All @@ -71,7 +71,7 @@ describe('ReactElement', function() {
});

it('coerces the key to a string', function() {
var element = React.createFactory(ComponentFactory)({
var element = React.createFactory(ComponentClass)({
key: 12,
foo: '56'
});
Expand All @@ -83,7 +83,7 @@ describe('ReactElement', function() {

it('treats a null key as omitted but warns', function() {
spyOn(console, 'warn');
var element = React.createFactory(ComponentFactory)({
var element = React.createFactory(ComponentClass)({
key: null,
foo: '56'
});
Expand All @@ -98,7 +98,7 @@ describe('ReactElement', function() {
});

it('preserves the context on the element', function() {
var Component = React.createFactory(ComponentFactory);
var Component = React.createFactory(ComponentClass);
var element;

var Wrapper = React.createClass({
Expand All @@ -120,7 +120,7 @@ describe('ReactElement', function() {
});

it('preserves the owner on the element', function() {
var Component = React.createFactory(ComponentFactory);
var Component = React.createFactory(ComponentClass);
var element;

var Wrapper = React.createClass({
Expand All @@ -144,7 +144,7 @@ describe('ReactElement', function() {
it('merges an additional argument onto the children prop', function() {
spyOn(console, 'warn');
var a = 1;
var element = React.createFactory(ComponentFactory)({
var element = React.createFactory(ComponentClass)({
children: 'text'
}, a);
expect(element.props.children).toBe(a);
Expand All @@ -153,7 +153,7 @@ describe('ReactElement', function() {

it('does not override children if no rest args are provided', function() {
spyOn(console, 'warn');
var element = React.createFactory(ComponentFactory)({
var element = React.createFactory(ComponentClass)({
children: 'text'
});
expect(element.props.children).toBe('text');
Expand All @@ -162,7 +162,7 @@ describe('ReactElement', function() {

it('overrides children if null is provided as an argument', function() {
spyOn(console, 'warn');
var element = React.createFactory(ComponentFactory)({
var element = React.createFactory(ComponentClass)({
children: 'text'
}, null);
expect(element.props.children).toBe(null);
Expand All @@ -172,14 +172,14 @@ describe('ReactElement', function() {
it('merges rest arguments onto the children prop in an array', function() {
spyOn(console, 'warn');
var a = 1, b = 2, c = 3;
var element = React.createFactory(ComponentFactory)(null, a, b, c);
var element = React.createFactory(ComponentClass)(null, a, b, c);
expect(element.props.children).toEqual([1, 2, 3]);
expect(console.warn.argsForCall.length).toBe(0);
});

it('warns for keys for arrays of elements in rest args', function() {
spyOn(console, 'warn');
var Component = React.createFactory(ComponentFactory);
var Component = React.createFactory(ComponentClass);

Component(null, [ Component(), Component() ]);

Expand All @@ -191,7 +191,7 @@ describe('ReactElement', function() {

it('warns for keys for iterables of elements in rest args', function() {
spyOn(console, 'warn');
var Component = React.createFactory(ComponentFactory);
var Component = React.createFactory(ComponentClass);

var iterable = {
'@@iterator': function() {
Expand All @@ -215,7 +215,7 @@ describe('ReactElement', function() {

it('does not warns for arrays of elements with keys', function() {
spyOn(console, 'warn');
var Component = React.createFactory(ComponentFactory);
var Component = React.createFactory(ComponentClass);

Component(null, [ Component({key: '#1'}), Component({key: '#2'}) ]);

Expand All @@ -224,7 +224,7 @@ describe('ReactElement', function() {

it('does not warns for iterable elements with keys', function() {
spyOn(console, 'warn');
var Component = React.createFactory(ComponentFactory);
var Component = React.createFactory(ComponentClass);

var iterable = {
'@@iterator': function() {
Expand All @@ -248,7 +248,7 @@ describe('ReactElement', function() {

it('warns for numeric keys on objects in rest args', function() {
spyOn(console, 'warn');
var Component = React.createFactory(ComponentFactory);
var Component = React.createFactory(ComponentClass);

Component(null, { 1: Component(), 2: Component() });

Expand All @@ -260,7 +260,7 @@ describe('ReactElement', function() {

it('does not warn for numeric keys in entry iterables in rest args', function() {
spyOn(console, 'warn');
var Component = React.createFactory(ComponentFactory);
var Component = React.createFactory(ComponentClass);

var iterable = {
'@@iterator': function() {
Expand All @@ -282,7 +282,7 @@ describe('ReactElement', function() {

it('does not warn when the element is directly in rest args', function() {
spyOn(console, 'warn');
var Component = React.createFactory(ComponentFactory);
var Component = React.createFactory(ComponentClass);

Component(null, Component(), Component());

Expand All @@ -291,7 +291,7 @@ describe('ReactElement', function() {

it('does not warn when the array contains a non-element', function() {
spyOn(console, 'warn');
var Component = React.createFactory(ComponentFactory);
var Component = React.createFactory(ComponentClass);

Component(null, [ {}, {} ]);

Expand Down