Skip to content

Commit

Permalink
Merge pull request #4861 from zpao/symbol-test-node4
Browse files Browse the repository at this point in the history
Better simulate Symbol-less environment
  • Loading branch information
zpao committed Sep 13, 2015
2 parents 2fcf549 + d54fa9e commit 0cc8af3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/isomorphic/classic/element/ReactElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ var assign = require('Object.assign');

// The Symbol used to tag the ReactElement type. If there is no native Symbol
// nor polyfill, then a plain number is used for performance.
var TYPE_SYMBOL = (typeof Symbol === 'function' && Symbol.for &&
Symbol.for('react.element')) || 0xeac7;
var TYPE_SYMBOL =
(typeof Symbol === 'function' && Symbol.for && Symbol.for('react.element')) ||
0xeac7;

var RESERVED_PROPS = {
key: true,
Expand Down
12 changes: 11 additions & 1 deletion src/isomorphic/classic/element/__tests__/ReactElement-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@ var ReactTestUtils;

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

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

// Delete the native Symbol if we have one to ensure we test the
// unpolyfilled environment.
delete global.Symbol;
originalSymbol = global.Symbol;
global.Symbol = undefined;

React = require('React');
ReactDOM = require('ReactDOM');
Expand All @@ -38,6 +40,14 @@ describe('ReactElement', function() {
});
});

afterEach(function() {
global.Symbol = originalSymbol;
});

it('uses the fallback value when in an environment without Symbol', function() {
expect(<div />.$$typeof).toBe(0xeac7);
});

it('returns a complete element according to spec', function() {
var element = React.createFactory(ComponentClass)();
expect(element.type).toBe(ComponentClass);
Expand Down

0 comments on commit 0cc8af3

Please sign in to comment.