|
1 | 1 | import 'ember-source/types'; |
2 | 2 | import '@glint/environment-ember-loose'; |
3 | 3 |
|
4 | | -import Helper from '@ember/component/helper'; |
5 | 4 |
|
6 | 5 | import { expectTypeOf } from 'expect-type'; |
| 6 | +import type Owner from '@ember/owner'; |
| 7 | + |
| 8 | +/************************ |
| 9 | + * The Helper |
| 10 | + ************************/ |
| 11 | +import Helper from '@ember/component/helper'; |
7 | 12 | import { pageTitle } from 'ember-page-title'; |
8 | 13 |
|
9 | | -expectTypeOf(new pageTitle()).toMatchTypeOf<Helper<any>>(); |
| 14 | +let instance = new pageTitle({} as Owner); |
| 15 | + |
| 16 | +expectTypeOf(instance).toMatchTypeOf<Helper<any>>(); |
| 17 | +expectTypeOf<ReturnType<typeof instance['compute']>>().toBeString(/* an empty string, but still a string */); |
| 18 | + |
| 19 | +/************************ |
| 20 | + * The Service |
| 21 | + ************************/ |
| 22 | +import PageTitleService from 'ember-page-title/services/page-title'; |
| 23 | +import type Service from '@ember/service'; |
| 24 | + |
| 25 | +let service = new PageTitleService({} as Owner); |
| 26 | + |
| 27 | +expectTypeOf(service).toMatchTypeOf<Service>(); |
| 28 | +expectTypeOf(service.tokens).toBeArray(); |
| 29 | +expectTypeOf(service.tokens[0]).toMatchTypeOf<object | undefined>(); |
| 30 | +expectTypeOf<NonNullable<typeof service.tokens[0]>>() |
| 31 | + .toMatchTypeOf<{ |
| 32 | + id: string, title?: string, |
| 33 | + separator?: string; |
| 34 | + prepend?: boolean; |
| 35 | + replace?: boolean; |
| 36 | + front?: unknown; |
| 37 | + }>(); |
| 38 | + |
| 39 | +expectTypeOf<PageTitleService['tokens']>().toBeArray(); |
| 40 | +expectTypeOf<PageTitleService['sortedTokens']>().toBeArray(); |
| 41 | +expectTypeOf<ReturnType<PageTitleService['toString']>>().toBeString(); |
| 42 | +expectTypeOf<PageTitleService['titleDidUpdate']>().toMatchTypeOf<(title: string) => void>(); |
| 43 | +expectTypeOf<PageTitleService['remove']>().toMatchTypeOf<(id: string) => void>(); |
| 44 | + |
| 45 | +expectTypeOf<PageTitleService['push']>() |
| 46 | + .toMatchTypeOf<(token: { id: string }) => void>(); |
| 47 | +expectTypeOf<PageTitleService['push']>() |
| 48 | + .toMatchTypeOf<(token: { id: string, title: string }) => void>(); |
| 49 | + |
| 50 | +// @ts-expect-error |
| 51 | +expectTypeOf<PageTitleService['push']>().toMatchTypeOf<(token: undefined) => void>(); |
0 commit comments