@samitouri / QOS-React-2 / commits / a293d75f75

Test that ReactErrorUtils module can be shimmed

We do this in www

Andrew Clark committed Mar 1, 2017 at 12:48 UTC a293d75f753b01db2cf47ddbaaae68bb08e755f2
2 files changed +27
scripts/fiber/tests-passing.txt
+2
@@ -1695,6 +1695,7 @@ src/renderers/shared/utils/__tests__/ReactErrorUtils-test.js
1695 * should return null if no error is thrown (development)
1696 * can nest with same debug name (development)
1697 * does not return nested errors (development)
1698 +* can be shimmed (development)
1699 * it should rethrow errors caught by invokeGuardedCallbackAndCatchFirstError (production)
1700 * should call the callback the passed arguments (production)
1701 * should call the callback with the provided context (production)
@@ -1702,6 +1703,7 @@ src/renderers/shared/utils/__tests__/ReactErrorUtils-test.js
1703 * should return null if no error is thrown (production)
1704 * can nest with same debug name (production)
1705 * does not return nested errors (production)
1706 +* can be shimmed (production)
1707
1708 src/renderers/shared/utils/__tests__/accumulateInto-test.js
1709 * throws if the second item is null
src/renderers/shared/utils/__tests__/ReactErrorUtils-test.js
+25
@@ -106,5 +106,30 @@ describe('ReactErrorUtils', () => {
106 expect(err3).toBe(null); // Returns null because inner error was already captured
107 expect(err2).toBe(err1);
108 });
109 +
110 + it(`can be shimmed (${environment})`, () => {
111 + const ops = [];
112 + // Override the original invokeGuardedCallback
113 + ReactErrorUtils.invokeGuardedCallback = function(name, func, context, a) {
114 + ops.push(a);
115 + try {
116 + func.call(context, a);
117 + } catch (error) {
118 + return error;
119 + }
120 + return null;
121 + };
122 +
123 + var err = new Error('foo');
124 + var callback = function() {
125 + throw err;
126 + };
127 + ReactErrorUtils.invokeGuardedCallbackAndCatchFirstError('foo', callback, null, 'somearg');
128 + expect(() => ReactErrorUtils.rethrowCaughtError()).toThrow(err);
129 + // invokeGuardedCallbackAndCatchFirstError and rethrowCaughtError close
130 + // over ReactErrorUtils.invokeGuardedCallback so should use the
131 + // shimmed version.
132 + expect(ops).toEqual(['somearg']);
133 + });
134 }
135 });