This repository was archived by the owner on Aug 4, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.js
More file actions
96 lines (93 loc) · 2.46 KB
/
test.js
File metadata and controls
96 lines (93 loc) · 2.46 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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
'use strict';
const assert = require('assert');
require('./index.js');
describe('not', () => {
it('should work with boolean', () => {
assert.equal(true.not, !true);
assert.equal(false.not, !false);
});
it('should work with number', () => {
assert.equal((0).not, !0);
assert.equal((1).not, !1);
Array(100)
.fill(0)
.map(() => Math.random())
.forEach(n => assert.equal(n.not, !n));
Array(100)
.fill(0)
.map(() => Math.floor(Math.random() * (10 - -10)) + -10)
.forEach(n => assert.equal(n.not, !n));
});
it('should work with string', () => {
assert.equal(''.not, !'');
assert.equal('string'.not, !'string');
});
it('should work with array', () => {
const arr = [false, 1, '', 2, 0, 3];
arr.not.forEach((element, i) => assert.equal(element, [
true, false, true, false, true, false,
][i]));
});
describe('with function', () => {
it('should work with function', () => {
function fb() {
return true;
}
function fn() {
return 1;
}
function fs() {
return 'string';
}
assert.equal(fb.not(), !fb());
assert.equal(fn.not(), !fn());
assert.equal(fs.not(), !fs());
});
it('should work with arrow function', () => {
const fb = () => true;
const fn = () => 1;
const fs = () => 'string';
assert.equal(fb.not(), !fb());
assert.equal(fn.not(), !fn());
assert.equal(fs.not(), !fs());
});
});
describe('with object', () => {
const obj = {
f() {
return true;
},
truly: true,
};
it('should work with getter', () => {
assert.equal(obj.not.f(), !obj.f());
assert.equal(obj.not.truly, !obj.truly);
});
it('shouldnt work with setter', () => {
assert.throws(() => { obj.not.truly = 'truly'; }, TypeError);
});
it('should work with in', () => {
assert.equal('a' in { a: 0 }.not, false);
assert.equal('b' in { a: 0 }.not, true);
});
it('shouldnt work with delete', () => {
assert.throws(() => delete obj.not.truly, TypeError);
});
it('should work with constructor', () => {
class Truly {
valueOf() {
return true;
}
}
class Falsy {
valueOf() {
return false;
}
}
assert.equal(+new Falsy.not().valueOf(), +new Truly().valueOf());
});
it('should be chainable', () => {
assert(obj.not.not.truly);
});
});
});