|
2 | 2 |
|
3 | 3 | var referee = require("@sinonjs/referee");
|
4 | 4 | var createStub = require("../lib/sinon/stub");
|
5 |
| -var createStubInstance = require("../lib/sinon/stub").createStubInstance; |
6 | 5 | var createSpy = require("../lib/sinon/spy");
|
7 | 6 | var createProxy = require("../lib/sinon/proxy");
|
8 | 7 | var match = require("@sinonjs/samsam").createMatcher;
|
@@ -3139,157 +3138,6 @@ describe("stub", function () {
|
3139 | 3138 | });
|
3140 | 3139 | });
|
3141 | 3140 |
|
3142 |
| - describe(".createStubInstance", function () { |
3143 |
| - it("stubs existing methods", function () { |
3144 |
| - var Class = function () { |
3145 |
| - return; |
3146 |
| - }; |
3147 |
| - Class.prototype.method = function () { |
3148 |
| - return; |
3149 |
| - }; |
3150 |
| - |
3151 |
| - var stub = createStubInstance(Class); |
3152 |
| - stub.method.returns(3); |
3153 |
| - assert.equals(3, stub.method()); |
3154 |
| - }); |
3155 |
| - |
3156 |
| - it("throws with no methods to stub", function () { |
3157 |
| - var Class = function () { |
3158 |
| - return; |
3159 |
| - }; |
3160 |
| - |
3161 |
| - assert.exception( |
3162 |
| - function () { |
3163 |
| - createStubInstance(Class); |
3164 |
| - }, |
3165 |
| - { |
3166 |
| - message: |
3167 |
| - "Found no methods on object to which we could apply mutations", |
3168 |
| - } |
3169 |
| - ); |
3170 |
| - }); |
3171 |
| - |
3172 |
| - it("doesn't call the constructor", function () { |
3173 |
| - var Class = function (a, b) { |
3174 |
| - var c = a + b; |
3175 |
| - throw c; |
3176 |
| - }; |
3177 |
| - Class.prototype.method = function () { |
3178 |
| - return; |
3179 |
| - }; |
3180 |
| - |
3181 |
| - var stub = createStubInstance(Class); |
3182 |
| - refute.exception(function () { |
3183 |
| - stub.method(3); |
3184 |
| - }); |
3185 |
| - }); |
3186 |
| - |
3187 |
| - it("retains non function values", function () { |
3188 |
| - var TYPE = "some-value"; |
3189 |
| - var Class = function () { |
3190 |
| - return; |
3191 |
| - }; |
3192 |
| - Class.prototype.method = function () { |
3193 |
| - return; |
3194 |
| - }; |
3195 |
| - Class.prototype.type = TYPE; |
3196 |
| - |
3197 |
| - var stub = createStubInstance(Class); |
3198 |
| - assert.equals(TYPE, stub.type); |
3199 |
| - }); |
3200 |
| - |
3201 |
| - it("has no side effects on the prototype", function () { |
3202 |
| - var proto = { |
3203 |
| - method: function () { |
3204 |
| - throw new Error("error"); |
3205 |
| - }, |
3206 |
| - }; |
3207 |
| - var Class = function () { |
3208 |
| - return; |
3209 |
| - }; |
3210 |
| - Class.prototype = proto; |
3211 |
| - |
3212 |
| - var stub = createStubInstance(Class); |
3213 |
| - refute.exception(stub.method); |
3214 |
| - assert.exception(proto.method); |
3215 |
| - }); |
3216 |
| - |
3217 |
| - it("throws exception for non function params", function () { |
3218 |
| - var types = [{}, 3, "hi!"]; |
3219 |
| - |
3220 |
| - for (var i = 0; i < types.length; i++) { |
3221 |
| - // yes, it's silly to create functions in a loop, it's also a test |
3222 |
| - // eslint-disable-next-line no-loop-func |
3223 |
| - assert.exception(function () { |
3224 |
| - createStubInstance(types[i]); |
3225 |
| - }); |
3226 |
| - } |
3227 |
| - }); |
3228 |
| - |
3229 |
| - it("allows providing optional overrides", function () { |
3230 |
| - var Class = function () { |
3231 |
| - return; |
3232 |
| - }; |
3233 |
| - Class.prototype.method = function () { |
3234 |
| - return; |
3235 |
| - }; |
3236 |
| - |
3237 |
| - var stub = createStubInstance(Class, { |
3238 |
| - method: createStub().returns(3), |
3239 |
| - }); |
3240 |
| - |
3241 |
| - assert.equals(3, stub.method()); |
3242 |
| - }); |
3243 |
| - |
3244 |
| - it("allows providing optional returned values", function () { |
3245 |
| - var Class = function () { |
3246 |
| - return; |
3247 |
| - }; |
3248 |
| - Class.prototype.method = function () { |
3249 |
| - return; |
3250 |
| - }; |
3251 |
| - |
3252 |
| - var stub = createStubInstance(Class, { |
3253 |
| - method: 3, |
3254 |
| - }); |
3255 |
| - |
3256 |
| - assert.equals(3, stub.method()); |
3257 |
| - }); |
3258 |
| - |
3259 |
| - it("allows providing null as a return value", function () { |
3260 |
| - var Class = function () { |
3261 |
| - return; |
3262 |
| - }; |
3263 |
| - Class.prototype.method = function () { |
3264 |
| - return; |
3265 |
| - }; |
3266 |
| - |
3267 |
| - var stub = createStubInstance(Class, { |
3268 |
| - method: null, |
3269 |
| - }); |
3270 |
| - |
3271 |
| - assert.equals(null, stub.method()); |
3272 |
| - }); |
3273 |
| - |
3274 |
| - it("throws an exception when trying to override non-existing property", function () { |
3275 |
| - var Class = function () { |
3276 |
| - return; |
3277 |
| - }; |
3278 |
| - Class.prototype.method = function () { |
3279 |
| - return; |
3280 |
| - }; |
3281 |
| - |
3282 |
| - assert.exception( |
3283 |
| - function () { |
3284 |
| - createStubInstance(Class, { |
3285 |
| - foo: createStub().returns(3), |
3286 |
| - }); |
3287 |
| - }, |
3288 |
| - { message: "Cannot stub foo. Property does not exist!" } |
3289 |
| - ); |
3290 |
| - }); |
3291 |
| - }); |
3292 |
| - |
3293 | 3141 | describe(".callThrough", function () {
|
3294 | 3142 | it("does not call original function when arguments match conditional stub", function () {
|
3295 | 3143 | // We need a function here because we can't wrap properties that are already stubs
|
|
0 commit comments