-
Notifications
You must be signed in to change notification settings - Fork 47k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Mock ReactDOM for Fiber Tests (#7206)
We currently write all our tests against the DOM implementation. I need a way to run the Fiber tests against it. But I don't want to take on any package dependencies on Fiber modules yet. There's a problem with jest right now where you can't globally mock modules that already exist. So I have to add a global call to jest.mock. Luckily we already have a way to test the useCreateElement paths using a feature flag. I won't activate this flag in travis until it passes, but the idea is to run all three variants in travis. I'm not sure that invoking rAF and rIC synchronously is the best way to test this since it doesn't capture the backwards compatibility aspect. I.e. the fact that people might be relying on the synchronous nature in real apps too. It's a start. Ideally, jest would have these built-in.
- Loading branch information
1 parent
1f31357
commit c06a68a
Showing
4 changed files
with
31 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,11 @@ | ||
/* eslint-disable */ | ||
global.__DEV__ = true; | ||
|
||
// For testing DOM Fiber, we synchronously invoke all the scheduling. | ||
global.requestAnimationFrame = function(callback) { | ||
callback(); | ||
}; | ||
|
||
global.requestIdleCallback = function(callback) { | ||
callback({ timeRemaining() { return Infinity; } }); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/** | ||
* Copyright 2013-2015, Facebook, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
var ReactDOMFeatureFlags = require('ReactDOMFeatureFlags'); | ||
|
||
var useFiber = ReactDOMFeatureFlags.useFiber; | ||
|
||
module.exports = | ||
useFiber ? require('ReactDOMFiber') : require.requireActual('ReactDOM'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ | |
|
||
var ReactDOMFeatureFlags = { | ||
useCreateElement: true, | ||
useFiber: false, | ||
}; | ||
|
||
module.exports = ReactDOMFeatureFlags; |