@samitouri / QOS-React-2 / commits / 102fafce7f

Add a simple production-mode sanity check test

Ben Alpert committed Aug 19, 2015 at 19:53 UTC 102fafce7f92b11b834e0af04f9bff05faed9aed
1 file changed +90
src/renderers/dom/__tests__/ReactDOMProduction-test.js new
+90
@@ -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 +});