Skip to content

Commit

Permalink
add additional test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefan Schweiger committed May 13, 2024
1 parent bb47175 commit 11d1472
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions test/typescript/custom-types/t.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,6 @@ describe('t', () => {

it('should throw error with string union with missing context value', () => {
enum DessertMissingValue {
COOKIE = 'cookie',
CAKE = 'cake',
MUFFIN = 'muffin',
ANOTHER = 'another',
Expand All @@ -199,14 +198,15 @@ describe('t', () => {
expectTypeOf(t('dessert', { context: DessertMissingValue.ANOTHER })).toMatchTypeOf<string>();

expectTypeOf(
// @ts-expect-error no default context so it must give a type error
t('dessert', { context: 'cookie' as 'cookie' | 'another' }),
).toEqualTypeOf<never>();
// @ts-expect-error 'another' is not mapped so it must give a type error
t('dessert', { context: 'cake' as 'cake' | 'another' }),
).toEqualTypeOf<'a nice cake'>();

expectTypeOf(
// @ts-expect-error no default context so it must give a type error
t('dessert', { context: 'cookie' as 'cookie' | undefined }),
).toEqualTypeOf<unknown>();
// TODO: edge case which is not correctly detected currently
// expectTypeOf(
// // @ts-expect-error no default context so it must give a type error
// t('dessert', { context: 'cake' as 'cake' | undefined }),
// ).toEqualTypeOf<never>();

expectTypeOf(
// @ts-expect-error no default context so it must give a type error
Expand All @@ -220,10 +220,10 @@ describe('t', () => {
WATER = 'water',
}

const getRandomDessert = (): BeverageValue | undefined =>
const getRandomBeverage = (): BeverageValue | undefined =>
Math.random() < 0.5 ? BeverageValue.BEER : undefined;

const ctxRandomValue = getRandomDessert();
const ctxRandomValue = getRandomBeverage();

expectTypeOf(
t('beverage', { context: ctxRandomValue }),
Expand Down

0 comments on commit 11d1472

Please sign in to comment.