Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 17 additions & 28 deletions packages/use-i18n/src/__typetests__/namespaceTranslation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,43 +16,34 @@ test('i18n - namespaceTranslation', () => {
const { namespaceTranslation } = useI18n<Locale, Locales>()

// Single key
expect(namespaceTranslation('hello')).type.toRaiseError(
`Argument of type '"hello"' is not assignable to parameter of type '"doe" | "describe"'`,
)
expect(namespaceTranslation).type.not.toBeCallableWith('hello')

// Multiple keys
expect(namespaceTranslation('doe.john')).type.toRaiseError(
`Argument of type '"doe.john"' is not assignable to parameter of type '"doe" | "describe"'`,
)
expect(namespaceTranslation).type.not.toBeCallableWith('doe.john')

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

expect(namespaceTranslation('doe')('doesnotexists')).type.toRaiseError(
`Expected 2 arguments, but got 1.`,
)
expect(namespaceTranslation('doe')).type.not.toBeCallableWith('doesnotexists')

// With a param
expect(namespaceTranslation('doe')('child')).type.toRaiseError(
`Expected 2 arguments, but got 1.`,
)
expect(namespaceTranslation('doe')).type.not.toBeCallableWith('child')
expect(
namespaceTranslation('doe')('child', {
name: 'Name',
}),
).type.toBe<string>()
expect(
namespaceTranslation('doe')('doesnotexists', {
expect(namespaceTranslation('doe')).type.not.toBeCallableWith(
'doesnotexists',
{
name: 'Name',
}),
).type.toRaiseError()
expect(
namespaceTranslation('doe')('child', {
doesnotexists: 'Name',
}),
).type.toRaiseError()
},
)
expect(namespaceTranslation('doe')).type.not.toBeCallableWith('child', {
doesnotexists: 'Name',
})

expect(namespaceTranslation('doe')('child', {})).type.toRaiseError()
expect(namespaceTranslation('doe')('child')).type.toRaiseError()
expect(namespaceTranslation('doe')).type.not.toBeCallableWith('child', {})
expect(namespaceTranslation('doe')).type.not.toBeCallableWith('child')

// With multiple params
expect(
Expand All @@ -62,12 +53,10 @@ test('i18n - namespaceTranslation', () => {
}),
).type.toBe<string>()

expect(namespaceTranslation('describe')('john', {})).type.toRaiseError()
expect(namespaceTranslation('describe')('john')).type.toRaiseError()
expect(namespaceTranslation('describe')).type.not.toBeCallableWith('john', {})
expect(namespaceTranslation('describe')).type.not.toBeCallableWith('john')

// Required generic
const { namespaceTranslation: namespaceTranslation2 } = useI18n<Locale>()
expect(namespaceTranslation2('test')).type.toRaiseError(
`Argument of type '"test"' is not assignable to parameter of type`,
)
expect(namespaceTranslation2).type.not.toBeCallableWith('test')
})
24 changes: 10 additions & 14 deletions packages/use-i18n/src/__typetests__/t.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,25 @@ const { t } = useI18n<{
test('i18n - t', () => {
expect(t('hello')).type.toBe<string>()
// Single key
expect(t('keydoesnotexists')).type.toRaiseError()
expect(t).type.not.toBeCallableWith('keydoesnotexists')

// Multiple keys
expect(t('doe.john')).type.toBe<string>()
expect(t('doe.doesnotexists')).type.toRaiseError()
expect(t).type.not.toBeCallableWith('doe.doesnotexists')

// With a param
expect(
t('doe.child', {
name: 'Name',
}),
).type.toBe<string>()
expect(
t('doe.doesnotexists', {
name: 'Name',
}),
).type.toRaiseError()
expect(t).type.not.toBeCallableWith('doe.doesnotexists', {
name: 'Name',
})

expect(t('doe.child', {})).type.toRaiseError(
"Argument of type '{}' is not assignable to parameter of type",
)
expect(t).type.not.toBeCallableWith('doe.child', {})

expect(t('doe.child')).type.toRaiseError('Expected 2 arguments, but got 1')
expect(t).type.not.toBeCallableWith('doe.child')

// With multiple params
expect(
Expand All @@ -44,8 +40,8 @@ test('i18n - t', () => {
}),
).type.toBe<string>()

expect(t('describe.john', {})).type.toRaiseError()
expect(t('describe.john')).type.toRaiseError()
expect(t).type.not.toBeCallableWith('describe.john', {})
expect(t).type.not.toBeCallableWith('describe.john')

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

// Required generic
const { t: t2 } = useI18n()
expect(t2('test')).type.toRaiseError()
expect(t2).type.not.toBeCallableWith('test')
})
Loading