Test that ReactErrorUtils module can be shimmed

We do this in www
This commit is contained in:
Andrew Clark committed 2017-03-01 14:38:48 -08:00
1 parent 5881371b61
commit a293d75f75
2 files changed
+27

No files matched your search

@@ -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']);
});
}
});