mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
Added init() dev block to ReactTestUtils
This commit is contained in:
@@ -184,6 +184,7 @@ function uglifyConfig(mangle) {
|
||||
},
|
||||
mangle: mangle ? {
|
||||
screw_ie8: true,
|
||||
toplevel: true,
|
||||
} : false,
|
||||
};
|
||||
}
|
||||
|
||||
+35
-25
@@ -486,19 +486,7 @@ function buildSimulators() {
|
||||
}
|
||||
}
|
||||
|
||||
// Rebuild ReactTestUtils.Simulate whenever event plugins are injected
|
||||
var oldInjectEventPluginOrder = EventPluginHub.injection.injectEventPluginOrder;
|
||||
EventPluginHub.injection.injectEventPluginOrder = function() {
|
||||
oldInjectEventPluginOrder.apply(this, arguments);
|
||||
buildSimulators();
|
||||
};
|
||||
var oldInjectEventPlugins = EventPluginHub.injection.injectEventPluginsByName;
|
||||
EventPluginHub.injection.injectEventPluginsByName = function() {
|
||||
oldInjectEventPlugins.apply(this, arguments);
|
||||
buildSimulators();
|
||||
};
|
||||
|
||||
buildSimulators();
|
||||
|
||||
/**
|
||||
* Exports:
|
||||
@@ -537,18 +525,40 @@ function makeNativeSimulator(eventType) {
|
||||
};
|
||||
}
|
||||
|
||||
Object.keys(topLevelTypes).forEach(function(eventType) {
|
||||
// Event type is stored as 'topClick' - we transform that to 'click'
|
||||
var convenienceName = eventType.indexOf('top') === 0
|
||||
? eventType.charAt(3).toLowerCase() + eventType.substr(4)
|
||||
: eventType;
|
||||
/**
|
||||
* @param {!Element|ReactDOMComponent} domComponentOrNode
|
||||
* @param {?Event} nativeEventData Fake native event to use in SyntheticEvent.
|
||||
*/
|
||||
ReactTestUtils.SimulateNative[convenienceName] = makeNativeSimulator(
|
||||
eventType,
|
||||
);
|
||||
});
|
||||
function init() {
|
||||
// Rebuild ReactTestUtils.Simulate whenever event plugins are injected
|
||||
var oldInjectEventPluginOrder = EventPluginHub.injection.injectEventPluginOrder;
|
||||
EventPluginHub.injection.injectEventPluginOrder = function() {
|
||||
oldInjectEventPluginOrder.apply(this, arguments);
|
||||
buildSimulators();
|
||||
};
|
||||
var oldInjectEventPlugins = EventPluginHub.injection.injectEventPluginsByName;
|
||||
EventPluginHub.injection.injectEventPluginsByName = function() {
|
||||
oldInjectEventPlugins.apply(this, arguments);
|
||||
buildSimulators();
|
||||
};
|
||||
|
||||
buildSimulators();
|
||||
|
||||
Object.keys(topLevelTypes).forEach(function(eventType) {
|
||||
// Event type is stored as 'topClick' - we transform that to 'click'
|
||||
var convenienceName = eventType.indexOf('top') === 0
|
||||
? eventType.charAt(3).toLowerCase() + eventType.substr(4)
|
||||
: eventType;
|
||||
/**
|
||||
* @param {!Element|ReactDOMComponent} domComponentOrNode
|
||||
* @param {?Event} nativeEventData Fake native event to use in SyntheticEvent.
|
||||
*/
|
||||
ReactTestUtils.SimulateNative[convenienceName] = makeNativeSimulator(
|
||||
eventType,
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
if (__DEV__) {
|
||||
init();
|
||||
} else {
|
||||
throw new Error('ReactTestUtils requires DEV');
|
||||
}
|
||||
|
||||
module.exports = ReactTestUtils;
|
||||
|
||||
Reference in New Issue
Block a user