source: node_modules/@reduxjs/toolkit/src/tests/Tuple.test-d.ts

Last change on this file was a762898, checked in by istevanoska <ilinastevanoska@…>, 5 months ago

Added visualizations

  • Property mode set to 100644
File size: 2.2 KB
Line 
1import { Tuple } from '@reduxjs/toolkit'
2
3describe('type tests', () => {
4 test('compatibility is checked between described types', () => {
5 const stringTuple = new Tuple('')
6
7 expectTypeOf(stringTuple).toEqualTypeOf<Tuple<[string]>>()
8
9 expectTypeOf(stringTuple).toMatchTypeOf<Tuple<string[]>>()
10
11 expectTypeOf(stringTuple).not.toMatchTypeOf<Tuple<[string, string]>>()
12
13 const numberTuple = new Tuple(0, 1)
14
15 expectTypeOf(numberTuple).not.toMatchTypeOf<Tuple<string[]>>()
16 })
17
18 test('concat is inferred properly', () => {
19 const singleString = new Tuple('')
20
21 expectTypeOf(singleString).toEqualTypeOf<Tuple<[string]>>()
22
23 expectTypeOf(singleString.concat('')).toEqualTypeOf<
24 Tuple<[string, string]>
25 >()
26
27 expectTypeOf(singleString.concat([''] as const)).toMatchTypeOf<
28 Tuple<[string, string]>
29 >()
30 })
31
32 test('prepend is inferred properly', () => {
33 const singleString = new Tuple('')
34
35 expectTypeOf(singleString).toEqualTypeOf<Tuple<[string]>>()
36
37 expectTypeOf(singleString.prepend('')).toEqualTypeOf<
38 Tuple<[string, string]>
39 >()
40
41 expectTypeOf(singleString.prepend([''] as const)).toMatchTypeOf<
42 Tuple<[string, string]>
43 >()
44 })
45
46 test('push must match existing items', () => {
47 const stringTuple = new Tuple('')
48
49 expectTypeOf(stringTuple.push).toBeCallableWith('')
50
51 expectTypeOf(stringTuple.push).parameter(0).not.toBeNumber()
52 })
53
54 test('Tuples can be combined', () => {
55 const stringTuple = new Tuple('')
56
57 const numberTuple = new Tuple(0, 1)
58
59 expectTypeOf(stringTuple.concat(numberTuple)).toEqualTypeOf<
60 Tuple<[string, number, number]>
61 >()
62
63 expectTypeOf(stringTuple.prepend(numberTuple)).toEqualTypeOf<
64 Tuple<[number, number, string]>
65 >()
66
67 expectTypeOf(numberTuple.concat(stringTuple)).toEqualTypeOf<
68 Tuple<[number, number, string]>
69 >()
70
71 expectTypeOf(numberTuple.prepend(stringTuple)).toEqualTypeOf<
72 Tuple<[string, number, number]>
73 >()
74
75 expectTypeOf(stringTuple.prepend(numberTuple)).not.toMatchTypeOf<
76 Tuple<[string, number, number]>
77 >()
78
79 expectTypeOf(stringTuple.concat(numberTuple)).not.toMatchTypeOf<
80 Tuple<[number, number, string]>
81 >()
82 })
83})
Note: See TracBrowser for help on using the repository browser.