@samitouri / QOS-React / commits / 17908c8ac9

Add test to ensure no duplicate values in ReactSymbols (#12845)

Brian Vaughn committed May 18, 2018 at 07:57 UTC 17908c8ac92333b32596378267e09b014af65cff
1 file changed +39
packages/shared/__tests__/ReactSymbols-test.internal.js new
+39
@@ -0,0 +1,39 @@
1 +/**
2 + * Copyright (c) 2013-present, Facebook, Inc.
3 + *
4 + * This source code is licensed under the MIT license found in the
5 + * LICENSE file in the root directory of this source tree.
6 + *
7 + * @emails react-core
8 + */
9 +'use strict';
10 +
11 +describe('ReactSymbols', () => {
12 + beforeEach(() => jest.resetModules());
13 +
14 + const expectToBeUnique = keyValuePairs => {
15 + const map = new Map();
16 + keyValuePairs.forEach(([key, value]) => {
17 + if (map.has(value)) {
18 + throw Error(
19 + `${key} value ${value.toString()} is the same as ${map.get(value)}.`,
20 + );
21 + }
22 + map.set(value, key);
23 + });
24 + };
25 +
26 + it('Symbol values should be unique', () => {
27 + expectToBeUnique(Object.entries(require('shared/ReactSymbols')));
28 + });
29 +
30 + it('numeric values should be unique', () => {
31 + const originalSymbolFor = global.Symbol.for;
32 + global.Symbol.for = null;
33 + try {
34 + expectToBeUnique(Object.entries(require('shared/ReactSymbols')));
35 + } finally {
36 + global.Symbol.for = originalSymbolFor;
37 + }
38 + });
39 +});