mirror of
https://github.com/zebrajr/react.git
synced 2025-12-07 00:20:28 +01:00
* Bump deps to Jest 22 * Prevent jsdom from logging intentionally thrown errors This relies on our existing special field that we use to mute errors. Perhaps, it would be better to instead rely on preventDefault() directly. I outlined a possible strategy here: https://github.com/facebook/react/issues/11098#issuecomment-355032539 * Update snapshots * Mock out a method called by ReactART that now throws * Calling .click() no longer works, dispatch event instead * Fix incorrect SVG element creation in test * Render SVG elements inside <svg> to avoid extra warnings * Fix range input test to use numeric value * Fix creating SVG element in test * Replace brittle test that relied on jsdom behavior The test passed in jsdom due to its implementation details. The original intention was to test the mutation method, but it was removed a while ago. Following @nhunzaker's suggestion, I moved the tests to ReactDOMInput and adjusted them to not rely on implementation details. * Add a workaround for the expected extra client-side warning This is a bit ugly but it's just two places. I think we can live with this. * Only warn once for mismatches caused by bad attribute casing We used to warn both about bad casing and about a mismatch. The mismatch warning was a bit confusing. We didn't know we warned twice because jsdom didn't faithfully emulate SVG. This changes the behavior to only leave the warning about bad casing if that's what caused the mismatch. It also adjusts the test to have an expectation that matches the real world behavior. * Add an expected warning per comment in the same test
51 lines
1.6 KiB
JavaScript
51 lines
1.6 KiB
JavaScript
/* eslint-disable */
|
|
|
|
const NODE_ENV = process.env.NODE_ENV;
|
|
if (NODE_ENV !== 'development' && NODE_ENV !== 'production') {
|
|
throw new Error('NODE_ENV must either be set to development or production.');
|
|
}
|
|
global.__DEV__ = NODE_ENV === 'development';
|
|
|
|
global.requestAnimationFrame = function(callback) {
|
|
setTimeout(callback);
|
|
};
|
|
|
|
global.requestIdleCallback = function(callback) {
|
|
return setTimeout(() => {
|
|
callback({
|
|
timeRemaining() {
|
|
return Infinity;
|
|
},
|
|
});
|
|
});
|
|
};
|
|
|
|
global.cancelIdleCallback = function(callbackID) {
|
|
clearTimeout(callbackID);
|
|
};
|
|
|
|
// By default React console.error()'s any errors, caught or uncaught.
|
|
// However it is annoying to assert that a warning fired each time
|
|
// we assert that there is an exception in our tests. This lets us
|
|
// opt out of extra console error reporting for most tests except
|
|
// for the few that specifically test the logging by shadowing this
|
|
// property. In real apps, it would usually not be defined at all.
|
|
Error.prototype.suppressReactErrorLogging = true;
|
|
|
|
if (typeof window !== 'undefined') {
|
|
// Same as above.
|
|
DOMException.prototype.suppressReactErrorLogging = true;
|
|
|
|
// Also prevent JSDOM from logging intentionally thrown errors.
|
|
// TODO: it might make sense to do it the other way around.
|
|
// https://github.com/facebook/react/issues/11098#issuecomment-355032539
|
|
window.addEventListener('error', event => {
|
|
if (event.error != null && event.error.suppressReactErrorLogging) {
|
|
event.preventDefault();
|
|
}
|
|
});
|
|
|
|
// Mock for ReactART.
|
|
HTMLCanvasElement.prototype.getContext = () => ({});
|
|
}
|