Better simulate Symbol-less environment

This ensures that our tests expecting Symbol not to exist pass.
This commit is contained in:
Paul O’Shannessy
2015-09-13 13:15:26 -07:00
parent 2fcf54939b
commit d54fa9e563
2 changed files with 14 additions and 3 deletions
@@ -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,
@@ -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(<div />.$$typeof).toBe(0xeac7);
});
it('returns a complete element according to spec', function() {
var element = React.createFactory(ComponentClass)();
expect(element.type).toBe(ComponentClass);