@samitouri / QOS-React-2 / commits / d54fa9e563

Better simulate Symbol-less environment

This ensures that our tests expecting Symbol not to exist pass.

Paul O’Shannessy committed Sep 13, 2015 at 13:15 UTC d54fa9e563d968112f5461274dc4e9d2aa6ed35c
2 files changed +14 -3
src/isomorphic/classic/element/ReactElement.js
+3 -2
@@ -17,8 +17,9 @@ var assign = require('Object.assign');
17
18 // The Symbol used to tag the ReactElement type. If there is no native Symbol
19 // nor polyfill, then a plain number is used for performance.
20 -var TYPE_SYMBOL = (typeof Symbol === 'function' && Symbol.for &&
21 - Symbol.for('react.element')) || 0xeac7;
20 +var TYPE_SYMBOL =
21 + (typeof Symbol === 'function' && Symbol.for && Symbol.for('react.element')) ||
22 + 0xeac7;
23
24 var RESERVED_PROPS = {
25 key: true,
src/isomorphic/classic/element/__tests__/ReactElement-test.js
+11 -1
@@ -20,13 +20,15 @@ var ReactTestUtils;
20
21 describe('ReactElement', function() {
22 var ComponentClass;
23 + var originalSymbol;
24
25 beforeEach(function() {
26 require('mock-modules').dumpCache();
27
28 // Delete the native Symbol if we have one to ensure we test the
29 // unpolyfilled environment.
29 - delete global.Symbol;
30 + originalSymbol = global.Symbol;
31 + global.Symbol = undefined;
32
33 React = require('React');
34 ReactDOM = require('ReactDOM');
@@ -38,6 +40,14 @@ describe('ReactElement', function() {
40 });
41 });
42
43 + afterEach(function() {
44 + global.Symbol = originalSymbol;
45 + });
46 +
47 + it('uses the fallback value when in an environment without Symbol', function() {
48 + expect(<div />.$$typeof).toBe(0xeac7);
49 + });
50 +
51 it('returns a complete element according to spec', function() {
52 var element = React.createFactory(ComponentClass)();
53 expect(element.type).toBe(ComponentClass);