Skip to content

Commit 5fa72c2

Browse files
committed
Merge pull request facebook#4666 from spicyj/prod
Add a simple production-mode sanity check test
2 parents ea827eb + 102fafc commit 5fa72c2

File tree

1 file changed

+90
-0
lines changed

1 file changed

+90
-0
lines changed
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
/**
2+
* Copyright 2013-2015, Facebook, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the BSD-style license found in the
6+
* LICENSE file in the root directory of this source tree. An additional grant
7+
* of patent rights can be found in the PATENTS file in the same directory.
8+
*
9+
* @emails react-core
10+
*/
11+
12+
'use strict';
13+
14+
describe('ReactDOMProduction', function() {
15+
var oldProcess;
16+
17+
var React;
18+
var ReactDOM;
19+
20+
beforeEach(function() {
21+
__DEV__ = true;
22+
oldProcess = process;
23+
global.process = {env: {NODE_ENV: 'production'}};
24+
25+
require('mock-modules').dumpCache();
26+
React = require('React');
27+
ReactDOM = require('ReactDOM');
28+
});
29+
30+
afterEach(function() {
31+
__DEV__ = false;
32+
global.process = oldProcess;
33+
});
34+
35+
it('should use prod fbjs', function() {
36+
var warning = require('warning');
37+
38+
spyOn(console, 'error');
39+
warning(false, 'Do cows go moo?');
40+
expect(console.error.argsForCall.length).toBe(0);
41+
});
42+
43+
it('should use prod React', function() {
44+
spyOn(console, 'error');
45+
46+
// no key warning
47+
void <div>{[<span />]}</div>;
48+
49+
expect(console.error.argsForCall.length).toBe(0);
50+
});
51+
52+
it('should handle a simple flow', function() {
53+
var Component = React.createClass({
54+
render: function() {
55+
return <span>{this.props.children}</span>;
56+
},
57+
});
58+
59+
var container = document.createElement('div');
60+
var inst = ReactDOM.render(
61+
<div className="blue">
62+
<Component key={1}>A</Component>
63+
<Component key={2}>B</Component>
64+
<Component key={3}>C</Component>
65+
</div>,
66+
container
67+
);
68+
69+
expect(container.firstChild).toBe(inst);
70+
expect(inst.className).toBe('blue');
71+
expect(inst.textContent).toBe('ABC');
72+
73+
ReactDOM.render(
74+
<div className="red">
75+
<Component key={2}>B</Component>
76+
<Component key={1}>A</Component>
77+
<Component key={3}>C</Component>
78+
</div>,
79+
container
80+
);
81+
82+
expect(inst.className).toBe('red');
83+
expect(inst.textContent).toBe('BAC');
84+
85+
ReactDOM.unmountComponentAtNode(container);
86+
87+
expect(container.childNodes.length).toBe(0);
88+
});
89+
90+
});

0 commit comments

Comments
 (0)