|
1 | 1 | 'use strict';
|
2 |
| -require('../common'); |
| 2 | +const common = require('../common'); |
3 | 3 | const assert = require('assert');
|
4 | 4 |
|
5 | 5 | // This test ensures that assert.CallTracker.calls() works as intended.
|
@@ -78,3 +78,51 @@ assert.throws(
|
78 | 78 | callsNoop();
|
79 | 79 | tracker.verify();
|
80 | 80 | }
|
| 81 | + |
| 82 | +{ |
| 83 | + function func() {} |
| 84 | + const tracker = new assert.CallTracker(); |
| 85 | + const callsfunc = tracker.calls(func); |
| 86 | + assert.strictEqual(callsfunc.length, 0); |
| 87 | +} |
| 88 | + |
| 89 | +{ |
| 90 | + function func(a, b, c = 2) {} |
| 91 | + const tracker = new assert.CallTracker(); |
| 92 | + const callsfunc = tracker.calls(func); |
| 93 | + assert.strictEqual(callsfunc.length, 2); |
| 94 | +} |
| 95 | + |
| 96 | +{ |
| 97 | + function func(a, b, c = 2) {} |
| 98 | + delete func.length; |
| 99 | + const tracker = new assert.CallTracker(); |
| 100 | + const callsfunc = tracker.calls(func); |
| 101 | + assert.strictEqual(Object.hasOwn(callsfunc, 'length'), false); |
| 102 | +} |
| 103 | + |
| 104 | +{ |
| 105 | + const ArrayIteratorPrototype = Reflect.getPrototypeOf( |
| 106 | + Array.prototype.values() |
| 107 | + ); |
| 108 | + const { next } = ArrayIteratorPrototype; |
| 109 | + ArrayIteratorPrototype.next = common.mustNotCall( |
| 110 | + '%ArrayIteratorPrototype%.next' |
| 111 | + ); |
| 112 | + Object.prototype.get = common.mustNotCall('%Object.prototype%.get'); |
| 113 | + |
| 114 | + const customPropertyValue = Symbol(); |
| 115 | + function func(a, b, c = 2) { |
| 116 | + return a + b + c; |
| 117 | + } |
| 118 | + func.customProperty = customPropertyValue; |
| 119 | + Object.defineProperty(func, 'length', { get: common.mustNotCall() }); |
| 120 | + const tracker = new assert.CallTracker(); |
| 121 | + const callsfunc = tracker.calls(func); |
| 122 | + assert.strictEqual(Object.hasOwn(callsfunc, 'length'), true); |
| 123 | + assert.strictEqual(callsfunc.customProperty, customPropertyValue); |
| 124 | + assert.strictEqual(callsfunc(1, 2, 3), 6); |
| 125 | + |
| 126 | + ArrayIteratorPrototype.next = next; |
| 127 | + delete Object.prototype.get; |
| 128 | +} |
0 commit comments