Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e308a03

Browse files
SimenBSunil Pai
authored and
Sunil Pai
committed
chore: make tests compatible with Jest 24 (facebook#15779)
* chore: make tests compatible with Jest 24 * remove fake rafs * rollback jsdom for localstorage compat * Apply suggestions from code review Co-Authored-By: Sunil Pai <[email protected]> * chore: cleanup lockfile
1 parent 5fa99b5 commit e308a03

File tree

9 files changed

+833
-897
lines changed

9 files changed

+833
-897
lines changed

packages/eslint-plugin-react-hooks/__tests__/ESLintRuleExhaustiveDeps-test.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,6 @@ const tests = {
521521
// Valid because the ref is captured.
522522
code: `
523523
function useMyThing(myRef) {
524-
const myRef = useRef();
525524
useEffect(() => {
526525
const handleMove = () => {};
527526
const node = myRef.current;

packages/eslint-plugin-react-hooks/__tests__/ESLintRulesOfHooks-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ eslintTester.run('react-hooks', ReactHooksESLintRule, {
9595
useHook2 = () => { useState(); };
9696
({useHook: () => { useState(); }});
9797
({useHook() { useState(); }});
98-
const {useHook = () => { useState(); }} = {};
98+
const {useHook3 = () => { useState(); }} = {};
9999
({useHook = () => { useState(); }} = {});
100100
`,
101101
`

packages/react-dom/src/__tests__/ReactDOMServerIntegrationElements-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -651,7 +651,7 @@ describe('ReactDOMServerIntegration', () => {
651651
});
652652
});
653653

654-
describe('component hierarchies', async function() {
654+
describe('component hierarchies', function() {
655655
itRenders('single child hierarchies of components', async render => {
656656
const Component = props => <div>{props.children}</div>;
657657
let e = await render(

packages/react-dom/src/events/__tests__/ChangeEventPlugin-test.internal.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,7 @@ describe('ChangeEventPlugin', () => {
3737
ReactFeatureFlags = require('shared/ReactFeatureFlags');
3838
// TODO pull this into helper method, reduce repetition.
3939
// mock the browser APIs which are used in schedule:
40-
// - requestAnimationFrame should pass the DOMHighResTimeStamp argument
4140
// - calling 'window.postMessage' should actually fire postmessage handlers
42-
global.requestAnimationFrame = function(cb) {
43-
return setTimeout(() => {
44-
cb(Date.now());
45-
});
46-
};
4741
const originalAddEventListener = global.addEventListener;
4842
let postMessageCallback;
4943
global.addEventListener = function(eventName, callback, useCapture) {

packages/react/src/__tests__/ReactCoffeeScriptClass-test.coffee

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,3 +543,4 @@ describe 'ReactCoffeeScriptClass', ->
543543
node = ReactDOM.findDOMNode(instance)
544544
expect(node).toBe container.firstChild
545545
undefined
546+
undefined

scripts/jest/config.base.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,11 @@ module.exports = {
2121
collectCoverageFrom: ['packages/**/*.js'],
2222
timers: 'fake',
2323
snapshotSerializers: [require.resolve('jest-snapshot-serializer-raw')],
24+
// Jest changed from `about:blank` to `http://localhost` default in 24.5 (https://github.com/facebook/jest/pull/6792)
25+
// in order to address https://github.com/facebook/jest/issues/6766. If one uses `about:blank` in [email protected] or
26+
// newer, it fails with `SecurityError: localStorage is not available for opaque origins`. However, some of React's
27+
// tests depend on `about:blank` being the domain (for e.g. `url` in `img` tags). So we set `about:blank` here to
28+
// keep the current behavior and make sure to keep the version of JSDOM to version lower than 11.12. This will have
29+
// to be addressed properly when Jest 25 is released, as it will come with a newer version of JSDOM.
30+
testURL: 'about:blank',
2431
};

scripts/jest/preprocessor.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ module.exports = {
6969
}
7070
: {}
7171
)
72-
).code;
72+
);
7373
}
7474
return src;
7575
},

scripts/jest/setupEnvironment.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@ global.__PROFILE__ = NODE_ENV === 'development';
99
global.__UMD__ = false;
1010

1111
if (typeof window !== 'undefined') {
12-
global.requestAnimationFrame = function(callback) {
13-
setTimeout(callback);
14-
};
15-
1612
global.requestIdleCallback = function(callback) {
1713
return setTimeout(() => {
1814
callback({

0 commit comments

Comments
 (0)