-
Notifications
You must be signed in to change notification settings - Fork 48.4k
/
Copy pathReactIncrementalErrorReplay-test.internal.js
46 lines (37 loc) · 1.58 KB
/
ReactIncrementalErrorReplay-test.internal.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @jest-environment node
*/
'use strict';
describe('ReactIncrementalErrorReplay-test', () => {
const React = require('react');
const ReactTestRenderer = require('react-test-renderer');
it('copies all keys when stashing potentially failing work', () => {
// Note: this test is fragile and relies on internals.
// We almost always try to avoid such tests, but here the cost of
// the list getting out of sync (and causing subtle bugs in rare cases)
// is higher than the cost of maintaining the test.
// This is the method we're going to test.
// If this is no longer used, you can delete this test file.;
const assignFiberPropertiesInDEV = gate(flags => flags.new)
? require('../ReactFiber.new').assignFiberPropertiesInDEV
: require('../ReactFiber.old').assignFiberPropertiesInDEV;
// Get a real fiber.
const realFiber = ReactTestRenderer.create(<div />).root._currentFiber();
const stash = assignFiberPropertiesInDEV(null, realFiber);
// Verify we get all the same fields.
expect(realFiber).toEqual(stash);
// Mutate the original.
for (const key in realFiber) {
realFiber[key] = key + '_' + Math.random();
}
expect(realFiber).not.toEqual(stash);
// Verify we can still "revert" to the stashed properties.
expect(assignFiberPropertiesInDEV(realFiber, stash)).toBe(realFiber);
expect(realFiber).toEqual(stash);
});
});