Skip to content

Commit b1f6049

Browse files
cellogtimdorr
authored andcommitted
convert the compose test to typescript (reduxjs#3509)
Former-commit-id: 48a7734
1 parent f9dd81a commit b1f6049

File tree

1 file changed

+18
-17
lines changed

1 file changed

+18
-17
lines changed

test/compose.spec.js renamed to test/compose.spec.ts

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { compose } from '../'
1+
import { compose } from '..'
22

33
describe('Utils', () => {
44
describe('compose', () => {
55
it('composes from right to left', () => {
6-
const double = x => x * 2
7-
const square = x => x * x
6+
const double = (x: number) => x * 2
7+
const square = (x: number) => x * x
88
expect(compose(square)(5)).toBe(25)
99
expect(
1010
compose(
@@ -22,10 +22,10 @@ describe('Utils', () => {
2222
})
2323

2424
it('composes functions from right to left', () => {
25-
const a = next => x => next(x + 'a')
26-
const b = next => x => next(x + 'b')
27-
const c = next => x => next(x + 'c')
28-
const final = x => x
25+
const a = (next: (x: string) => string) => (x: string) => next(x + 'a')
26+
const b = (next: (x: string) => string) => (x: string) => next(x + 'b')
27+
const c = (next: (x: string) => string) => (x: string) => next(x + 'c')
28+
const final = (x: string) => x
2929

3030
expect(
3131
compose(
@@ -51,14 +51,15 @@ describe('Utils', () => {
5151
})
5252

5353
it('throws at runtime if argument is not a function', () => {
54-
const square = x => x * x
55-
const add = (x, y) => x + y
54+
type sFunc = (x: number, y: number) => number
55+
const square = (x: number, _: number) => x * x
56+
const add = (x: number, y: number) => x + y
5657

5758
expect(() =>
5859
compose(
5960
square,
6061
add,
61-
false
62+
(false as unknown) as sFunc
6263
)(1, 2)
6364
).toThrow()
6465
expect(() =>
@@ -72,28 +73,28 @@ describe('Utils', () => {
7273
compose(
7374
square,
7475
add,
75-
true
76+
(true as unknown) as sFunc
7677
)(1, 2)
7778
).toThrow()
7879
expect(() =>
7980
compose(
8081
square,
8182
add,
82-
NaN
83+
(NaN as unknown) as sFunc
8384
)(1, 2)
8485
).toThrow()
8586
expect(() =>
8687
compose(
8788
square,
8889
add,
89-
'42'
90+
('42' as unknown) as sFunc
9091
)(1, 2)
9192
).toThrow()
9293
})
9394

9495
it('can be seeded with multiple arguments', () => {
95-
const square = x => x * x
96-
const add = (x, y) => x + y
96+
const square = (x: number, _: number) => x * x
97+
const add = (x: number, y: number) => x + y
9798
expect(
9899
compose(
99100
square,
@@ -103,9 +104,9 @@ describe('Utils', () => {
103104
})
104105

105106
it('returns the first given argument if given no functions', () => {
106-
expect(compose()(1, 2)).toBe(1)
107+
expect(compose<number>()(1, 2)).toBe(1)
107108
expect(compose()(3)).toBe(3)
108-
expect(compose()()).toBe(undefined)
109+
expect(compose()(undefined)).toBe(undefined)
109110
})
110111

111112
it('returns the first function if given only one', () => {

0 commit comments

Comments
 (0)