@samitouri / QOS-React-2 / commits / 279792f891
Fork 0

The library for web and native user interfaces.

Fix `EventPluginRegistry` Unit Tests

Dumping the mock cache isn't dirying the modules, so we have to unit test a different way. If we can fix our unit test framework, we should revert this. Also, I added strict mode to `EventPluginRegistry.js`.

yungsters committed Jun 13, 2013 at 20:27 UTC 279792f891cee4d2e5685bc6cb4dee6498a3c9b0
3 files changed +31 -3
src/event/EventPluginRegistry.js
+23
@@ -3,6 +3,8 @@
3 * @typechecks
4 */
5
6 +"use strict";
7 +
8 var invariant = require('invariant');
9
10 /**
@@ -200,6 +202,27 @@ var EventPluginRegistry = {
202 }
203 }
204 return null;
205 + },
206 +
207 + /**
208 + * Exposed for unit testing.
209 + * @private
210 + */
211 + _resetEventPlugins: function() {
212 + EventPluginOrder = null;
213 + for (var pluginName in namesToPlugins) {
214 + if (namesToPlugins.hasOwnProperty(pluginName)) {
215 + delete namesToPlugins[pluginName];
216 + }
217 + }
218 + EventPluginRegistry.plugins.length = 0;
219 + var registrationNames = EventPluginRegistry.registrationNames;
220 + for (var registrationName in registrationNames) {
221 + if (registrationNames.hasOwnProperty(registrationName)) {
222 + delete registrationNames[registrationName];
223 + }
224 + }
225 + EventPluginRegistry.registrationNamesKeys.length = 0;
226 }
227
228 };
src/event/__tests__/EventPluginRegistry-test.js
+1 -1
@@ -11,8 +11,8 @@ describe('EventPluginRegistry', function() {
11 var createPlugin;
12
13 beforeEach(function() {
14 - require('mock-modules').dumpCache();
14 EventPluginRegistry = require('EventPluginRegistry');
15 + EventPluginRegistry._resetEventPlugins();
16
17 createPlugin = function(properties) {
18 return merge({extractEvents: function() {}}, properties);
src/eventPlugins/__tests__/AnalyticsEventPlugin-test.js
+7 -2
@@ -24,21 +24,26 @@ var mocks = require('mocks');
24 describe('AnalyticsEventPlugin', function() {
25 var AnalyticsEventPluginFactory;
26 var EventPluginHub;
27 + var EventPluginRegistry;
28 var React;
29 + var ReactDefaultInjection;
30 var ReactEventEmitter;
31 var ReactEventTopLevelCallback;
32 var ReactTestUtils;
33
34 beforeEach(function() {
33 - require('mock-modules').dumpCache();
34 -
35 AnalyticsEventPluginFactory = require('AnalyticsEventPluginFactory');
36 EventPluginHub = require('EventPluginHub');
37 + EventPluginRegistry = require('EventPluginRegistry');
38 React = require('React');
39 + ReactDefaultInjection = require('ReactDefaultInjection');
40 ReactEventEmitter = require('ReactEventEmitter');
41 ReactEventTopLevelCallback = require('ReactEventTopLevelCallback');
42 ReactTestUtils = require('ReactTestUtils');
43
44 + EventPluginRegistry._resetEventPlugins();
45 + ReactDefaultInjection.inject();
46 +
47 ReactEventEmitter.ensureListening(false, ReactEventTopLevelCallback);
48 });
49