Skip to content

Commit 05f8543

Browse files
committed
chore: use .toBeCallableWith() in type test
1 parent b18edff commit 05f8543

File tree

2 files changed

+27
-43
lines changed

2 files changed

+27
-43
lines changed

packages/use-i18n/src/__typetests__/namespaceTranslation.test.ts

Lines changed: 17 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -16,43 +16,33 @@ test('i18n - namespaceTranslation', () => {
1616
const { namespaceTranslation } = useI18n<Locale, Locales>()
1717

1818
// Single key
19-
expect(namespaceTranslation('hello')).type.toRaiseError(
20-
`Argument of type '"hello"' is not assignable to parameter of type '"doe" | "describe"'`,
21-
)
22-
19+
expect(namespaceTranslation).type.not.toBeCallableWith('hello')
2320
// Multiple keys
24-
expect(namespaceTranslation('doe.john')).type.toRaiseError(
25-
`Argument of type '"doe.john"' is not assignable to parameter of type '"doe" | "describe"'`,
26-
)
21+
expect(namespaceTranslation).type.not.toBeCallableWith('doe.john')
2722

2823
expect(namespaceTranslation('doe')('john')).type.toBe<string>()
2924

30-
expect(namespaceTranslation('doe')('doesnotexists')).type.toRaiseError(
31-
`Expected 2 arguments, but got 1.`,
32-
)
25+
expect(namespaceTranslation('doe')).type.not.toBeCallableWith('doesnotexists')
3326

3427
// With a param
35-
expect(namespaceTranslation('doe')('child')).type.toRaiseError(
36-
`Expected 2 arguments, but got 1.`,
37-
)
28+
expect(namespaceTranslation('doe')).type.not.toBeCallableWith('child')
3829
expect(
3930
namespaceTranslation('doe')('child', {
4031
name: 'Name',
4132
}),
4233
).type.toBe<string>()
43-
expect(
44-
namespaceTranslation('doe')('doesnotexists', {
34+
expect(namespaceTranslation('doe')).type.not.toBeCallableWith(
35+
'doesnotexists',
36+
{
4537
name: 'Name',
46-
}),
47-
).type.toRaiseError()
48-
expect(
49-
namespaceTranslation('doe')('child', {
50-
doesnotexists: 'Name',
51-
}),
52-
).type.toRaiseError()
38+
},
39+
)
40+
expect(namespaceTranslation('doe')).type.not.toBeCallableWith('child', {
41+
doesnotexists: 'Name',
42+
})
5343

54-
expect(namespaceTranslation('doe')('child', {})).type.toRaiseError()
55-
expect(namespaceTranslation('doe')('child')).type.toRaiseError()
44+
expect(namespaceTranslation('doe')).type.not.toBeCallableWith('child', {})
45+
expect(namespaceTranslation('doe')).type.not.toBeCallableWith('child')
5646

5747
// With multiple params
5848
expect(
@@ -62,12 +52,10 @@ test('i18n - namespaceTranslation', () => {
6252
}),
6353
).type.toBe<string>()
6454

65-
expect(namespaceTranslation('describe')('john', {})).type.toRaiseError()
66-
expect(namespaceTranslation('describe')('john')).type.toRaiseError()
55+
expect(namespaceTranslation('describe')).type.not.toBeCallableWith('john', {})
56+
expect(namespaceTranslation('describe')).type.not.toBeCallableWith('john')
6757

6858
// Required generic
6959
const { namespaceTranslation: namespaceTranslation2 } = useI18n<Locale>()
70-
expect(namespaceTranslation2('test')).type.toRaiseError(
71-
`Argument of type '"test"' is not assignable to parameter of type`,
72-
)
60+
expect(namespaceTranslation2).type.not.toBeCallableWith('test')
7361
})

packages/use-i18n/src/__typetests__/t.test.tsx

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,29 +12,25 @@ const { t } = useI18n<{
1212
test('i18n - t', () => {
1313
expect(t('hello')).type.toBe<string>()
1414
// Single key
15-
expect(t('keydoesnotexists')).type.toRaiseError()
15+
expect(t).type.not.toBeCallableWith('keydoesnotexists')
1616

1717
// Multiple keys
1818
expect(t('doe.john')).type.toBe<string>()
19-
expect(t('doe.doesnotexists')).type.toRaiseError()
19+
expect(t).type.not.toBeCallableWith('doe.doesnotexists')
2020

2121
// With a param
2222
expect(
2323
t('doe.child', {
2424
name: 'Name',
2525
}),
2626
).type.toBe<string>()
27-
expect(
28-
t('doe.doesnotexists', {
29-
name: 'Name',
30-
}),
31-
).type.toRaiseError()
27+
expect(t).type.not.toBeCallableWith('doe.doesnotexists', {
28+
name: 'Name',
29+
})
3230

33-
expect(t('doe.child', {})).type.toRaiseError(
34-
"Argument of type '{}' is not assignable to parameter of type",
35-
)
31+
expect(t).type.not.toBeCallableWith('doe.child', {})
3632

37-
expect(t('doe.child')).type.toRaiseError('Expected 2 arguments, but got 1')
33+
expect(t).type.not.toBeCallableWith('doe.child')
3834

3935
// With multiple params
4036
expect(
@@ -44,8 +40,8 @@ test('i18n - t', () => {
4440
}),
4541
).type.toBe<string>()
4642

47-
expect(t('describe.john', {})).type.toRaiseError()
48-
expect(t('describe.john')).type.toRaiseError()
43+
expect(t).type.not.toBeCallableWith('describe.john', {})
44+
expect(t).type.not.toBeCallableWith('describe.john')
4945

5046
// With react components as param value
5147
expect(
@@ -60,5 +56,5 @@ test('i18n - t', () => {
6056

6157
// Required generic
6258
const { t: t2 } = useI18n()
63-
expect(t2('test')).type.toRaiseError()
59+
expect(t2).type.not.toBeCallableWith('test')
6460
})

0 commit comments

Comments
 (0)