|
111 | 111 | it('should be a function', function(){ |
112 | 112 | assert(typeof bogus.requireWithStubs === 'function'); |
113 | 113 | }); |
| 114 | + |
| 115 | + it('should return a promise', function(){ |
| 116 | + var p = bogus.requireWithStubs('blah', function(){}, function(){}); |
| 117 | + |
| 118 | + assert.equal(typeof p.then, 'function'); |
| 119 | + assert.equal(typeof p.catch, 'function'); |
| 120 | + }); |
114 | 121 | }); |
115 | 122 |
|
116 | 123 | describe('require method', function(){ |
|
120 | 127 | }); |
121 | 128 |
|
122 | 129 | describe('reset method', function(){ |
123 | | - it('should return all original implementations to their names', function(done){ |
124 | | - var define = requirejs.define, |
125 | | - modules = [], |
126 | | - moduleNames = [], |
127 | | - i, j, module, |
128 | | - defineStub; |
| 130 | + var modules; |
| 131 | + var defineStub; |
| 132 | + |
| 133 | + beforeEach(function(done){ |
| 134 | + var define = requirejs.define; |
| 135 | + var i; |
| 136 | + var moduleNames = []; |
| 137 | + var module; |
| 138 | + |
| 139 | + modules = []; |
129 | 140 |
|
130 | 141 | sandbox.stub(requirejs, 'defined', function(){ |
131 | 142 | return true; |
132 | 143 | }); |
133 | 144 |
|
134 | | - for (i = 0; i < 10; i++){ |
| 145 | + for (i = 0; i < 10; i++) { |
135 | 146 | module = { |
136 | 147 | name : getUniqueModuleName(), |
137 | 148 | originalImplementation : {name: 'original'}, |
|
146 | 157 | } |
147 | 158 |
|
148 | 159 | defineStub = sandbox.spy(requirejs, 'define'); |
149 | | - requirejs(moduleNames, function () { |
150 | | - bogus.reset(function(){ |
151 | | - j = 0; |
152 | | - modules.forEach(function(module, index){ |
153 | | - var call = defineStub.getCall(index); |
154 | 160 |
|
155 | | - assert.equal(call.args[0], module.name); |
156 | | - j++; |
157 | | - }); |
| 161 | + requirejs(moduleNames, function(){ |
| 162 | + done(); |
| 163 | + }); |
| 164 | + }); |
| 165 | + |
| 166 | + it('is a function', function(){ |
| 167 | + assert.equal(typeof bogus.reset, 'function'); |
| 168 | + }); |
| 169 | + |
| 170 | + it('returns a promise', function(){ |
| 171 | + var p = bogus.reset(); |
| 172 | + |
| 173 | + assert.equal(typeof p.then, 'function'); |
| 174 | + assert.equal(typeof p.catch, 'function'); |
| 175 | + }); |
| 176 | + |
| 177 | + it('returns all original implementations to their names and call a callback', function(done){ |
| 178 | + bogus.reset(function(){ |
| 179 | + modules.forEach(function(module, index){ |
| 180 | + var call = defineStub.getCall(index); |
| 181 | + |
| 182 | + assert.equal(call.args[0], module.name); |
| 183 | + }); |
| 184 | + |
| 185 | + done(); |
| 186 | + }); |
| 187 | + }); |
158 | 188 |
|
159 | | - assert.equal(j, modules.length); |
| 189 | + it('returns all original implementations to their names and resolves a returned promise', function(){ |
| 190 | + return bogus.reset().then(function(){ |
| 191 | + modules.forEach(function(module, index){ |
| 192 | + var call = defineStub.getCall(index); |
160 | 193 |
|
161 | | - done(); |
| 194 | + assert.equal(call.args[0], module.name); |
162 | 195 | }); |
163 | 196 | }); |
164 | 197 | }); |
|
0 commit comments