Skip to content

Commit 8281c16

Browse files
test(testing): update.
1 parent 15d03b8 commit 8281c16

12 files changed

Lines changed: 362 additions & 8 deletions
Lines changed: 54 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,59 @@
1+
// Class.
2+
import { Testing, TestingIt } from "../../lib";
13
import { TestingToBeArrayOf } from "../../lib/testing";
4+
// Execute.
5+
import { ExecuteSpec } from "../execute";
26

7+
const execute = true;
8+
const executeDescribe = true;
9+
const executeIt = true;
310

4-
const t = new TestingToBeArrayOf(
5-
true,
6-
true,
7-
{},
8-
false
9-
);
11+
if (execute) {
12+
const t = new Testing(
13+
executeDescribe,
14+
executeIt,
15+
);
1016

11-
t.toBeArrayOfBigInt([BigInt(1)]);
17+
const testingIt = new TestingIt(false);
18+
const test4 = new Testing(
19+
executeDescribe,
20+
executeIt,
21+
undefined,
22+
true,
23+
undefined,
24+
testingIt
25+
);
1226

27+
const test1 = new TestingToBeArrayOf();
28+
const test2 = new TestingToBeArrayOf(false, false, {it: [4, 2]}, true);
29+
const test3 = new TestingToBeArrayOf(false, false, undefined, true, undefined, testingIt);
30+
31+
test1.describe(`TestingToBeArrayOf true`, () => {
32+
test1
33+
.toBeArrayOfBigInt([BigInt(37), BigInt(27)])
34+
.toBeArrayOfDate([new Date(), new Date()])
35+
.toBeArrayOfDefined(['37', '47'])
36+
.toBeArrayOfFalse([false, false])
37+
.toBeArrayOfNull([null, null])
38+
.toBeArrayOfRegExp([new RegExp('b'), new RegExp('a')])
39+
.toBeArrayOfString(['a', 'b'])
40+
.toBeArrayOfSymbol([Symbol('a'), Symbol('b')])
41+
.toBeArrayOfTrue([true, true, true, true])
42+
.toBeArrayOfUndefined([undefined, undefined, undefined, undefined])
43+
});
44+
test2.describe(`TestingToBeArrayOf false`, () => {
45+
test2
46+
.toBeArrayOfDefined(['37', '47'])
47+
.toBeArrayOfNull([null, null])
48+
.toBeArrayOfSymbol([Symbol('a'), Symbol('b')])
49+
.toBeArrayOfUndefined([undefined, undefined, undefined, undefined])
50+
});
51+
// Uncomment to check `testingIt`.
52+
// test4.describe(`TestingToBeArrayOf testingIt`, () => {
53+
// test3
54+
// .toBeArrayOfDefined(['37', '47'])
55+
// .toBeArrayOfNull([null, null])
56+
// .toBeArrayOfSymbol([Symbol('a'), Symbol('b')])
57+
// .toBeArrayOfUndefined([undefined, undefined, undefined, undefined])
58+
// });
59+
}
Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,17 @@
11
import { TestingToBeBoolean } from "../../lib";
22

3-
const t = new TestingToBeBoolean(true, true);
3+
const execute = true;
4+
const executeDescribe = true;
5+
const executeIt = true;
46

7+
if (execute) {
8+
const t = new TestingToBeBoolean(
9+
executeDescribe,
10+
executeIt
11+
);
12+
t.describe(`TestingToBeBoolean`, () => {
13+
t
14+
.toBeBoolean(false)
15+
.toBeBooleanType(false);
16+
});
17+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { TestingToBeGreaterThan } from "../../lib";
2+
3+
const execute = true;
4+
const executeDescribe = true;
5+
const executeIt = true;
6+
7+
if (execute) {
8+
const t = new TestingToBeGreaterThan(
9+
executeDescribe,
10+
executeIt
11+
);
12+
13+
t.describe(`TestingToBeGreaterThan`, () => {
14+
t
15+
.toBeGreaterThan(37, 27)
16+
.toBeGreaterThanOrEqual(37, 37)
17+
});
18+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import { TestingToBeInstanceOf } from "../../lib";
2+
3+
const execute = true;
4+
const executeDescribe = true;
5+
const executeIt = true;
6+
7+
if (execute) {
8+
const t = new TestingToBeInstanceOf(
9+
executeDescribe,
10+
executeIt
11+
);
12+
t.describe(`TestingToBeInstanceOf`, () =>
13+
t
14+
.toBeInstanceOfArray([37, 27])
15+
.toBeInstanceOfBoolean(false)
16+
.toBeInstanceOfDate(new Date())
17+
18+
// Error.
19+
.toBeInstanceOfError(new Error('Error'))
20+
.toBeInstanceOfError(new RangeError('RangeError'))
21+
.toBeInstanceOfError(new ReferenceError('ReferenceError'))
22+
.toBeInstanceOfError(new SyntaxError('SyntaxError'))
23+
24+
.toBeInstanceOfFunction(function() {})
25+
.toBeInstanceOfMap(new Map())
26+
.toBeInstanceOfNumber(37)
27+
28+
// Object.
29+
.toBeInstanceOfObject({})
30+
.toBeInstanceOfObject(Object.create({}))
31+
.toBeInstanceOfPromise(new Promise((resolve, reject) => { resolve('resolve'); }))
32+
.toBeInstanceOfRangeError(new RangeError('Range'))
33+
.toBeInstanceOfReferenceError(new ReferenceError('Reference'))
34+
.toBeInstanceOfRegExp(new RegExp('RegExp'))
35+
.toBeInstanceOfSet(new Set('Set'))
36+
// .toBeInstanceOfStorage()
37+
.toBeInstanceOfString(new String('String'))
38+
39+
// Error
40+
.toBeInstanceOfSyntaxError(new SyntaxError('Syntax'))
41+
.toBeInstanceOfTypeError(new TypeError('type'))
42+
.toBeInstanceOfURIError(new URIError('URI'))
43+
44+
//
45+
.toBeInstanceOfWeakSet(new WeakSet())
46+
);
47+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { TestingToBeLessThan } from "../../lib";
2+
3+
const execute = true;
4+
const executeDescribe = true;
5+
const executeIt = true;
6+
7+
if (execute) {
8+
const t = new TestingToBeLessThan(
9+
executeDescribe,
10+
executeIt
11+
);
12+
13+
t.describe(`TestingToBeLessThan`, () => {
14+
t
15+
.toBeLessThan(27, 37)
16+
.toBeLessThanOrEqual(27, 27)
17+
});
18+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { TestingToBeNumber } from "../../lib";
2+
3+
const execute = true;
4+
const executeDescribe = true;
5+
const executeIt = true;
6+
7+
if (execute) {
8+
const t = new TestingToBeNumber(
9+
executeDescribe,
10+
executeIt
11+
);
12+
13+
t.describe(`TestingToBeNumber`, () => {
14+
t
15+
// .not.toBeNumber('a')
16+
.toBeNumber(27)
17+
.toBeNumberBetween(37, 27, 47)
18+
});
19+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { TestingToBeObject } from "../../lib";
2+
3+
const execute = true;
4+
const executeDescribe = true;
5+
const executeIt = true;
6+
7+
if (execute) {
8+
const t = new TestingToBeObject(
9+
executeDescribe,
10+
executeIt
11+
);
12+
13+
class ClassA {
14+
public string = 'test';
15+
public num = 27;
16+
}
17+
18+
const classA = new ClassA();
19+
20+
t.describe(`TestingToBeObject`, () => {
21+
t
22+
.toBeObject(t)
23+
.toBeObjectKey(classA, 'string')
24+
.toBeObjectKey(t, 'expect', false)
25+
.toBeObjectKeyIn(t, 'expect')
26+
.toBeObjectKeys(classA, ['string', 'num'])
27+
.toBeObjectKeysIn(t, ['expect', 'testingIt'])
28+
.toBeObjectSomeKeys(classA, ['string', 'test', 'num'])
29+
});
30+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { TestingToBeString } from "../../lib";
2+
3+
const execute = true;
4+
const executeDescribe = true;
5+
const executeIt = true;
6+
7+
if (execute) {
8+
const t = new TestingToBeString(
9+
executeDescribe,
10+
executeIt
11+
);
12+
t.describe(`TestingToBeString`, () =>
13+
t
14+
.toBeString('string')
15+
.toBeString(new String('string'))
16+
17+
.toBeStringIncludes('string number boolean', ['string', 'number', 'boolean'])
18+
.toBeStringIncludesSome('string number boolean', ['string', 'test', 'boolean'])
19+
20+
.toBeStringOfLength('toBeStringOfLength', 18)
21+
.toBeStringOfLengthBetween('toBeStringOfLengthBetween', 18, 27)
22+
23+
.toBeStringType('test')
24+
.toBeStringType(new String('test'), false)
25+
);
26+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import { TestingToBe } from "../../lib";
2+
3+
// TODO:
4+
const execute = true;
5+
const executeDescribe = true;
6+
const executeIt = true;
7+
8+
if (execute) {
9+
const t = new TestingToBe(
10+
executeDescribe,
11+
executeIt
12+
);
13+
14+
t.describe(`TestingToBe`, () =>
15+
t
16+
.toBeArray([27, 37])
17+
.toBeBigInt(BigInt(27))
18+
.toBeClass(TestingToBe)
19+
// .toBeCloseTo()
20+
.toBeDate(new Date())
21+
.toBeDefined('A')
22+
.toBeFalse(false)
23+
.toBeFalsy(false)
24+
.toBeFunction(() => {})
25+
.toBeInstance(t, TestingToBe)
26+
.toBeInstanceOf(t, TestingToBe)
27+
.toBeKey('PropertyKey')
28+
.toBeNaN(NaN)
29+
.toBeNegativeInfinity(-Infinity)
30+
.toBeNull(null)
31+
32+
// .toBePending(new Promise((resolve, reject) => {}))
33+
.toBePositiveInfinity(Infinity)
34+
35+
.toBeRegExp(new RegExp('a'))
36+
37+
.toBeRejected(new Promise((resolve, reject) => reject('any')))
38+
.toBeRejectedWith(new Promise((resolve, reject) => reject({test: 27})), {test: 27})
39+
// .toBeRejectedWithError(new Promise((resolve, reject) => { reject(new Error('Error')) }), Error, 'Error')
40+
41+
.toBeResolved(new Promise((resolve, reject) => resolve('any')))
42+
.toBeResolvedTo(new Promise((resolve, reject) => resolve({test: 27})), {test: 27})
43+
.toBeSymbol(Symbol('a'))
44+
45+
.toBeTrue(true)
46+
.toBeTruthy(true)
47+
.toBeUndefined(undefined)
48+
);
49+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import { TestingToHave } from "../../lib";
2+
3+
const execute = true;
4+
const executeDescribe = true;
5+
const executeIt = true;
6+
7+
if (execute) {
8+
const t = new TestingToHave(
9+
executeDescribe,
10+
executeIt
11+
);
12+
13+
class ClassA {
14+
public methodA(value?: any) {
15+
return "methodA";
16+
}
17+
public methodB(value?: any) {
18+
return "methodB";
19+
}
20+
public methodC(value?: any) {
21+
return "methodB";
22+
}
23+
}
24+
25+
const classA = new ClassA();
26+
27+
const el = document.createElement('div');
28+
el.className = 'foo bar baz';
29+
30+
t.describe(`TestingToHave`, () => {
31+
t
32+
.beforeEach(() => {
33+
spyOn(classA, "methodA");
34+
spyOn(classA, "methodB");
35+
spyOn(classA, "methodC");
36+
classA.methodB();
37+
classA.methodA();
38+
classA.methodA({test: 27});
39+
classA.methodC({test: 37});
40+
})
41+
.toHaveBeenCalled(() => classA.methodA)
42+
43+
// Spy multiple methods.
44+
.toHaveBeenCalled(() => [classA.methodA, classA.methodB])
45+
.toHaveBeenCalledBefore(() => [classA.methodB, classA.methodA])
46+
.toHaveBeenCalledOnceWith(`toHaveBeenCalledOnceWith`, () => classA.methodC, {test: 37})
47+
.toHaveBeenCalledWith(`toHaveBeenCalledWith`, () => classA.methodA, {test: 27})
48+
.toHaveClass(el, 'baz')
49+
.toHaveSize([27, 37, 47], 3)
50+
51+
// .toHaveSpyInteractions()
52+
});
53+
}

0 commit comments

Comments
 (0)