| 2338 | var callId = 0; |
| 2339 | |
| 2340 | function spy(object, property, types) { |
| 2341 | var descriptor, methodDesc; |
| 2342 | |
| 2343 | if (isEsModule(object)) { |
| 2344 | throw new TypeError("ES Modules cannot be spied"); |
| 2345 | } |
| 2346 | |
| 2347 | if (!property && typeof object === "function") { |
| 2348 | return spy.create(object); |
| 2349 | } |
| 2350 | |
| 2351 | if (!object && !property) { |
| 2352 | return spy.create(function() { |
| 2353 | return; |
| 2354 | }); |
| 2355 | } |
| 2356 | |
| 2357 | if (!types) { |
| 2358 | return wrapMethod(object, property, spy.create(object[property])); |
| 2359 | } |
| 2360 | |
| 2361 | descriptor = {}; |
| 2362 | methodDesc = getPropertyDescriptor(object, property); |
| 2363 | |
| 2364 | forEach(types, function(type) { |
| 2365 | descriptor[type] = spy.create(methodDesc[type]); |
| 2366 | }); |
| 2367 | |
| 2368 | return wrapMethod(object, property, descriptor); |
| 2369 | } |
| 2370 | |
| 2371 | function incrementCallCount() { |
| 2372 | this.called = true; |