Skip to content

Commit 62c284e

Browse files
committed
modify tests
1 parent 45c1d55 commit 62c284e

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

test/modify.test.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { expectError, expectType } from 'tsd';
2+
3+
import { modify, toUpper, add, identity, pipe, map } from '../es';
4+
5+
type Obj = {
6+
foo: string;
7+
bar: number;
8+
};
9+
10+
expectType<Obj>(modify('foo', toUpper, {} as Obj));
11+
expectType<Obj>(modify('bar', add(1), {} as Obj));
12+
expectType<Obj>(modify('foo', toUpper)({} as Obj));
13+
expectType<Obj>(modify('bar', add(1))({} as Obj));
14+
expectType<Obj>(modify('foo')(toUpper)({} as Obj));
15+
expectType<Obj>(modify('bar')(add(1))({} as Obj));
16+
expectType<Obj>(modify('foo')(toUpper, {} as Obj));
17+
expectType<Obj>(modify('bar')(add(1), {} as Obj));
18+
19+
// fails when function has wrong argument type
20+
expectError(modify('foo', add(1), {} as Obj));
21+
expectError(modify('bar', toUpper, {} as Obj));
22+
23+
// fails when key does not exist on Obj
24+
expectError(modify('unknownKey', toUpper, {} as Obj));
25+
26+
// works with generic fn
27+
expectType<Obj>(modify('foo', identity, {} as Obj));
28+
29+
// pipe and map sanity checks
30+
const f = pipe(
31+
map<Obj, Obj>(modify('foo', toUpper))
32+
);
33+
34+
expectType<Obj[]>(f([] as Obj[]));

0 commit comments

Comments
 (0)