Skip to content

Commit

Permalink
test(typings): standardize the way how we do tests
Browse files Browse the repository at this point in the history
Ref #978
  • Loading branch information
char0n committed Oct 6, 2019
1 parent e05ab63 commit c14bd95
Show file tree
Hide file tree
Showing 14 changed files with 85 additions and 58 deletions.
1 change: 0 additions & 1 deletion types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1167,7 +1167,6 @@ declare namespace RamdaAdjunct {
* Escapes the RegExp special characters.
*/
escapeRegExp(val: string): string;
escapeRegExp<T>(val: T): T;

/**
* Divides two numbers, where the second number is divided by the first number.
Expand Down
8 changes: 8 additions & 0 deletions types/test/allEqual.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
import * as RA from 'ramda-adjunct';

import { customIterable } from './helpers';

RA.allEqual([1, 2, 3, 4]); // $ExpectType boolean
RA.allEqual(['a', 'b', 'c', 'd']); // $ExpectType boolean
RA.allEqual([1, 'b', 2, 'd']); // $ExpectType boolean
RA.allEqual([]); // $ExpectType boolean

RA.allEqual(1); // $ExpectError
RA.allEqual({}); // $ExpectError
RA.allEqual(customIterable); // $ExpectError
6 changes: 6 additions & 0 deletions types/test/allEqualTo.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import * as RA from "ramda-adjunct";

import { customIterable } from './helpers';

RA.allEqualTo(1, [1, 2, 3, 4]); // $ExpectType boolean
RA.allEqualTo(1, []); // $ExpectType boolean
RA.allEqualTo(1)([1, 2, 3, 4]); // $ExpectType boolean
RA.allEqualTo(1)([]); // $ExpectType boolean

RA.allEqualTo(1, {}); // $ExpectError
RA.allEqualTo(1, 'a'); // $ExpectError
RA.allEqualTo(1, customIterable); // $ExpectError
6 changes: 6 additions & 0 deletions types/test/allIdentical.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import * as RA from "ramda-adjunct";

import { customIterable } from './helpers';

RA.allIdentical([1, 2, 3, 4]); // $ExpectType boolean
RA.allIdentical([]); // $ExpectType boolean

RA.allIdentical({}); // $ExpectError
RA.allIdentical('a'); // $ExpectError
RA.allIdentical(customIterable); // $ExpectError
6 changes: 6 additions & 0 deletions types/test/allIdenticalTo.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import * as RA from "ramda-adjunct";

import { customIterable } from './helpers';

RA.allIdenticalTo(1, [1, 2, 3, 4]); // $ExpectType boolean
RA.allIdenticalTo(1, []); // $ExpectType boolean
RA.allIdenticalTo(1)([]); // $ExpectType boolean

RA.allIdenticalTo('a', [1, 2]); // $ExpectError
RA.allIdenticalTo(1, customIterable); // $ExpectError
20 changes: 5 additions & 15 deletions types/test/allP.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,13 @@
import * as RA from 'ramda-adjunct';

/**
* Helpers.
*/

const customIterable = {
*[Symbol.iterator](): IterableIterator<number> {
yield 1;
yield 2;
yield 3;
},
};

/**
* Tests.
*/
import { customIterable } from './helpers';

RA.allP([1, 2]); // $ExpectType Promise<number[]>
RA.allP(['a', 'b']); // $ExpectType Promise<string[]>
RA.allP([1, 'a']); // $ExpectType Promise<(string | number)[]>
RA.allP([]); // $ExpectType Promise<never[]>
RA.allP(customIterable); // $ExpectType Promise<number[]>
RA.allP('abc'); // $ExpectType Promise<string[]>

RA.allP({}); // $ExpectError
RA.allP(1); // $ExpectError
20 changes: 5 additions & 15 deletions types/test/allSettledP.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,13 @@
import * as RA from 'ramda-adjunct';

/**
* Helpers.
*/

const customIterable = {
*[Symbol.iterator](): IterableIterator<number> {
yield 1;
yield 2;
yield 3;
},
};

/**
* Tests.
*/
import { customIterable } from './helpers';

RA.allSettledP([1, 2]); // $ExpectType Promise<SettledPromise<number>[]>
RA.allSettledP(['a', 'b']); // $ExpectType Promise<SettledPromise<string>[]>
RA.allSettledP([1, 'a']); // $ExpectType Promise<SettledPromise<string | number>[]>
RA.allSettledP([]); // $ExpectType Promise<SettledPromise<never>[]>
RA.allSettledP(customIterable); // $ExpectType Promise<SettledPromise<number>[]>
RA.allSettledP('abc'); // $ExpectType Promise<SettledPromise<string>[]>

RA.allSettledP({}); // $ExpectError
RA.allSettledP(1); // $ExpectError
19 changes: 4 additions & 15 deletions types/test/anyP.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,12 @@
import * as RA from 'ramda-adjunct';

/**
* Helpers.
*/

const customIterable = {
*[Symbol.iterator](): IterableIterator<number> {
yield 1;
yield 2;
yield 3;
},
};

/**
* Tests.
*/
import { customIterable } from './helpers';

RA.anyP([1, 2]); // $ExpectType Promise<number>
RA.anyP(['a', 'b']); // $ExpectType Promise<string>
RA.anyP([1, 'a']); // $ExpectType Promise<string | number>
RA.anyP([]); // $ExpectType Promise<never>
RA.anyP(customIterable); // $ExpectType Promise<number>

RA.anyP({}); // $ExpectError
RA.anyP(1); // $ExpectError
9 changes: 9 additions & 0 deletions types/test/appendFlipped.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
import * as RA from 'ramda-adjunct';

import { customIterable } from './helpers';

RA.appendFlipped([1, 2], 3); // $ExpectType number[]
RA.appendFlipped(['a', 'b'], 'c'); // $ExpectType string[]
RA.appendFlipped(['a', 2], 3); // $ExpectType (string | number)[]
RA.appendFlipped<number>([1, 2], 3); // $ExpectType number[]
RA.appendFlipped<string>(['a', 'b'], 'c'); // $ExpectType string[]

RA.appendFlipped<string>([1, 'b'], 'c'); // $ExpectError
RA.appendFlipped<string>([1, 'b'])('c'); // $ExpectError
RA.appendFlipped(1, 'c'); // $ExpectError
RA.appendFlipped(1)('c'); // $ExpectError
RA.appendFlipped(customIterable, 'c'); // $ExpectError
RA.appendFlipped(customIterable)('c'); // $ExpectError
9 changes: 9 additions & 0 deletions types/test/divideNum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,12 @@ RA.divideNum(2.0)(1.0); // $ExpectType number
RA.divideNum(0)(2.0); // $ExpectType number
RA.divideNum(0.0)(2.0); // $ExpectType number
RA.divideNum(-0.0)(2.0); // $ExpectType number

RA.divideNum('a', 'b'); // $ExpectError
RA.divideNum('a')('b'); // $ExpectError
RA.divideNum(1, undefined); // $ExpectError
RA.divideNum(1)(undefined); // $ExpectError
RA.divideNum(1, {}); // $ExpectError
RA.divideNum(1)({}); // $ExpectError
RA.divideNum({}, 1); // $ExpectError
RA.divideNum({})(1); // $ExpectError
14 changes: 9 additions & 5 deletions types/test/escapeRegExp.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import * as RA from 'ramda-adjunct';

RA.escapeRegExp('abc'); // $ExpectType string
RA.escapeRegExp(1); // $ExpectType 1
RA.escapeRegExp({}); // $ExpectType {}
RA.escapeRegExp<number>(1); // $ExpectType number
RA.escapeRegExp<null>(null); // $ExpectType null
RA.escapeRegExp<undefined>(undefined); // $ExpectType undefined
RA.escapeRegExp(''); // $ExpectType string

// tslint:disable-next-line:no-construct
RA.escapeRegExp(new String('')); // $ExpectError
RA.escapeRegExp(1); // $ExpectError
RA.escapeRegExp({}); // $ExpectError
RA.escapeRegExp(null); // $ExpectError
RA.escapeRegExp(undefined); // $ExpectError
RA.escapeRegExp([]); // $ExpectError
7 changes: 7 additions & 0 deletions types/test/helpers/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export const customIterable: Iterable<number> = {
*[Symbol.iterator](): IterableIterator<number> {
yield 1;
yield 2;
yield 3;
},
};
7 changes: 2 additions & 5 deletions types/test/isSparseArray.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import * as RA from 'ramda-adjunct';

/**
* Tests.
*/

RA.isSparseArray(new Array(3)); // $ExpectType boolean
RA.isSparseArray([1, , 3]); // tslint:disable-line no-sparse-arrays
// tslint:disable-next-line:no-sparse-arrays
RA.isSparseArray([1, , 3]); // $ExpectType boolean

RA.isSparseArray([1, 2, 3]); // $ExpectType boolean
RA.isSparseArray(new Array()); // $ExpectType boolean
Expand Down
11 changes: 9 additions & 2 deletions types/test/subtractValue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,15 @@ import * as RA from 'ramda-adjunct';

RA.subtractNum(3, 5); // $ExpectType number
RA.subtractNum(5, 3); // $ExpectType number
RA.subtractNum(3, 'foo'); // $ExpectError

RA.subtractNum(3)(5); // $ExpectType number
RA.subtractNum(5)(3); // $ExpectType number
RA.subtractNum(3)('foo'); // $ExpectError

RA.subtractNum('a', 'b'); // $ExpectError
RA.subtractNum('a')('b'); // $ExpectError
RA.subtractNum(1, undefined); // $ExpectError
RA.subtractNum(1)(undefined); // $ExpectError
RA.subtractNum(1, {}); // $ExpectError
RA.subtractNum(1)({}); // $ExpectError
RA.subtractNum({}, 1); // $ExpectError
RA.subtractNum({})(1); // $ExpectError

0 comments on commit c14bd95

Please sign in to comment.