Test that ReactErrorUtils module can be shimmed

We do this in www
This commit is contained in:
Andrew Clark 2017-03-01 12:48:02 -08:00
parent 5881371b61
commit a293d75f75
2 changed files with 27 additions and 0 deletions

View File

@ -1695,6 +1695,7 @@ src/renderers/shared/utils/__tests__/ReactErrorUtils-test.js
* should return null if no error is thrown (development)
* can nest with same debug name (development)
* does not return nested errors (development)
* can be shimmed (development)
* it should rethrow errors caught by invokeGuardedCallbackAndCatchFirstError (production)
* should call the callback the passed arguments (production)
* should call the callback with the provided context (production)
@ -1702,6 +1703,7 @@ src/renderers/shared/utils/__tests__/ReactErrorUtils-test.js
* should return null if no error is thrown (production)
* can nest with same debug name (production)
* does not return nested errors (production)
* can be shimmed (production)
src/renderers/shared/utils/__tests__/accumulateInto-test.js
* throws if the second item is null

View File

@ -106,5 +106,30 @@ describe('ReactErrorUtils', () => {
expect(err3).toBe(null); // Returns null because inner error was already captured
expect(err2).toBe(err1);
});
it(`can be shimmed (${environment})`, () => {
const ops = [];
// Override the original invokeGuardedCallback
ReactErrorUtils.invokeGuardedCallback = function(name, func, context, a) {
ops.push(a);
try {
func.call(context, a);
} catch (error) {
return error;
}
return null;
};
var err = new Error('foo');
var callback = function() {
throw err;
};
ReactErrorUtils.invokeGuardedCallbackAndCatchFirstError('foo', callback, null, 'somearg');
expect(() => ReactErrorUtils.rethrowCaughtError()).toThrow(err);
// invokeGuardedCallbackAndCatchFirstError and rethrowCaughtError close
// over ReactErrorUtils.invokeGuardedCallback so should use the
// shimmed version.
expect(ops).toEqual(['somearg']);
});
}
});