From d54fa9e563d968112f5461274dc4e9d2aa6ed35c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paul=20O=E2=80=99Shannessy?= Date: Sun, 13 Sep 2015 13:15:26 -0700 Subject: [PATCH] Better simulate Symbol-less environment This ensures that our tests expecting Symbol not to exist pass. --- src/isomorphic/classic/element/ReactElement.js | 5 +++-- .../classic/element/__tests__/ReactElement-test.js | 12 +++++++++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/isomorphic/classic/element/ReactElement.js b/src/isomorphic/classic/element/ReactElement.js index f24192b115..49d94b210c 100644 --- a/src/isomorphic/classic/element/ReactElement.js +++ b/src/isomorphic/classic/element/ReactElement.js @@ -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, diff --git a/src/isomorphic/classic/element/__tests__/ReactElement-test.js b/src/isomorphic/classic/element/__tests__/ReactElement-test.js index 2499eda816..d93aa2eee5 100644 --- a/src/isomorphic/classic/element/__tests__/ReactElement-test.js +++ b/src/isomorphic/classic/element/__tests__/ReactElement-test.js @@ -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'); @@ -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(
.$$typeof).toBe(0xeac7); + }); + it('returns a complete element according to spec', function() { var element = React.createFactory(ComponentClass)(); expect(element.type).toBe(ComponentClass);