tinyexpect 0.1.1 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/index.js +21 -8
- package/index.ts +24 -11
- package/package.json +1 -1
package/README.md
CHANGED
package/index.js
CHANGED
|
@@ -4,19 +4,17 @@ exports.expect = void 0;
|
|
|
4
4
|
function expect(v) {
|
|
5
5
|
return {
|
|
6
6
|
toBe: (a) => {
|
|
7
|
+
if (typeof v === "object") {
|
|
8
|
+
if (JSON.stringify(v) !== JSON.stringify(a)) {
|
|
9
|
+
throw new Error(`Objects are not equal`);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
7
12
|
if (v !== a) {
|
|
8
13
|
throw new Error(`Expected ${v} to be ${a}`);
|
|
9
14
|
}
|
|
10
15
|
},
|
|
11
16
|
eitherOr: (values) => {
|
|
12
|
-
|
|
13
|
-
for (let value of values) {
|
|
14
|
-
if (v === value) {
|
|
15
|
-
result = true;
|
|
16
|
-
break;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
if (result === false) {
|
|
17
|
+
if (!values.includes(v)) {
|
|
20
18
|
throw new Error(`Expected ${v} to be either of the following values:` +
|
|
21
19
|
JSON.stringify(values));
|
|
22
20
|
}
|
|
@@ -39,6 +37,21 @@ function expect(v) {
|
|
|
39
37
|
return;
|
|
40
38
|
}
|
|
41
39
|
expect(v).toBeNumberOrParsed();
|
|
40
|
+
},
|
|
41
|
+
toBeFalsy() {
|
|
42
|
+
if (v) {
|
|
43
|
+
throw new Error(`${v} is not falsy`);
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
toBeTruthy() {
|
|
47
|
+
if (!v) {
|
|
48
|
+
throw new Error(`${v} is not truthy`);
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
toBeDefined() {
|
|
52
|
+
if (typeof v === "undefined") {
|
|
53
|
+
throw new Error(`${v} is not defined`);
|
|
54
|
+
}
|
|
42
55
|
}
|
|
43
56
|
};
|
|
44
57
|
}
|
package/index.ts
CHANGED
|
@@ -1,19 +1,17 @@
|
|
|
1
1
|
export function expect(v: any) {
|
|
2
2
|
return {
|
|
3
3
|
toBe: (a: any) => {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
if (typeof v === "object"){
|
|
5
|
+
if (JSON.stringify(v) !== JSON.stringify(a)){
|
|
6
|
+
throw new Error(`Objects are not equal`)
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
if (v !== a) {
|
|
10
|
+
throw new Error(`Expected ${v} to be ${a}`)
|
|
11
|
+
}
|
|
7
12
|
},
|
|
8
13
|
eitherOr: (values: any[]) => {
|
|
9
|
-
|
|
10
|
-
for (let value of values) {
|
|
11
|
-
if (v === value) {
|
|
12
|
-
result = true
|
|
13
|
-
break
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
if (result === false) {
|
|
14
|
+
if (!values.includes(v)) {
|
|
17
15
|
throw new Error(
|
|
18
16
|
`Expected ${v} to be either of the following values:` +
|
|
19
17
|
JSON.stringify(values)
|
|
@@ -38,6 +36,21 @@ export function expect(v: any) {
|
|
|
38
36
|
return
|
|
39
37
|
}
|
|
40
38
|
expect(v).toBeNumberOrParsed()
|
|
39
|
+
},
|
|
40
|
+
toBeFalsy(){
|
|
41
|
+
if (v){
|
|
42
|
+
throw new Error(`${v} is not falsy`)
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
toBeTruthy(){
|
|
46
|
+
if (!v){
|
|
47
|
+
throw new Error(`${v} is not truthy`)
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
toBeDefined(){
|
|
51
|
+
if (typeof v === "undefined"){
|
|
52
|
+
throw new Error(`${v} is not defined`)
|
|
53
|
+
}
|
|
41
54
|
}
|
|
42
55
|
}
|
|
43
56
|
}
|