Mock modules properly in test runner
As an added bonus, the jasmine web interface now groups tests by file. Test Plan: grunt test passes on b2507066, the parent of 566f8b2e (which committed a workaround for buggy module mocking).
Ben Alpert committed
Nov 21, 2013 at 00:39 UTC
c7bb3af760d30c247b934ba5af893d119029e50b
2 files changed
+32
-1
src/test/all.js
+10
-1
@@ -10,7 +10,16 @@ require("mock-modules");
10
require("./mock-timers");
11
12
exports.enableTest = function(testID) {
13
- require("../" + testID);
13
+ describe(testID, function() {
14
+ var mockMap;
15
+ beforeEach(function() {
16
+ require("mock-modules").setMockMap(mockMap);
17
+ });
18
+
19
+ require("mock-modules").clearMockMap();
20
+ require("../" + testID);
21
+ mockMap = require("mock-modules").getMockMap();
22
+ });
23
};
24
25
exports.removeNextSiblings = function(node) {
src/test/mock-modules.js
+22
@@ -73,6 +73,28 @@ exports.dumpCache = function() {
73
return exports;
74
};
75
76
+exports.getMockMap = function() {
77
+ return explicitMockMap;
78
+};
79
+
80
+exports.clearMockMap = function() {
81
+ explicitMockMap = {};
82
+};
83
+
84
+exports.setMockMap = function(mockMap) {
85
+ exports.dumpCache();
86
+ exports.clearMockMap();
87
+ for (var id in mockMap) {
88
+ if (mockMap[id]) {
89
+ doMock(id);
90
+ } else {
91
+ doNotMock(id);
92
+ }
93
+ }
94
+
95
+ return exports;
96
+};
97
+
98
// Call this function to ensure that require(id) returns the actual
99
// exports object created by the module.
100
function doNotMock(id) {