-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathex6.test.js
More file actions
33 lines (24 loc) · 1.04 KB
/
ex6.test.js
File metadata and controls
33 lines (24 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
'use strict';
const { createEvenInstanceChecker } = require('./ex6');
function assert(condition, message) {
if (!condition) throw new Error(message || 'Assertion failed');
}
{
const Even = createEvenInstanceChecker();
assert(typeof Even === 'function', 'Expected checker to be callable/function-like');
// Ensure Symbol.hasInstance is used
assert(
typeof Even[Symbol.hasInstance] === 'function',
'Expected Symbol.hasInstance to be defined as a function'
);
assert((2 instanceof Even) === true, 'Expected even number to satisfy instanceof checker');
assert((3 instanceof Even) === false, 'Expected odd number to fail instanceof checker');
assert(('2' instanceof Even) === false, 'Expected non-number primitive to fail');
assert(({} instanceof Even) === false, 'Expected non-number object to fail');
const impostor = Object.create(Even.prototype);
assert(
(impostor instanceof Even) === false,
'Expected behavior based on Symbol.hasInstance semantics, not prototype duck typing'
);
}
console.log('ex6 tests passed');