mirror of
https://github.com/facebook/docusaurus.git
synced 2025-07-25 12:38:57 +02:00
test: fix ALL type errors in tests (#7487)
This commit is contained in:
parent
e2e40b8f5f
commit
d50fe3b670
37 changed files with 407 additions and 184 deletions
|
@ -25,7 +25,7 @@ describe('useTitleFormatter', () => {
|
|||
title: 'my site',
|
||||
titleDelimiter: '·',
|
||||
},
|
||||
});
|
||||
} as DocusaurusContext);
|
||||
expect(mockUseTitleFormatter('a page')).toBe('a page · my site');
|
||||
expect(mockUseTitleFormatter(undefined)).toBe('my site');
|
||||
expect(mockUseTitleFormatter(' ')).toBe('my site');
|
||||
|
|
|
@ -26,7 +26,7 @@ describe('useAlternatePageUtils', () => {
|
|||
const mockUseAlternatePageUtils = createUseAlternatePageUtilsMock({
|
||||
siteConfig: {baseUrl: '/', url: 'https://example.com'},
|
||||
i18n: {defaultLocale: 'en', currentLocale: 'en'},
|
||||
});
|
||||
} as DocusaurusContext);
|
||||
expect(
|
||||
mockUseAlternatePageUtils('/').createUrl({
|
||||
locale: 'zh-Hans',
|
||||
|
@ -51,7 +51,7 @@ describe('useAlternatePageUtils', () => {
|
|||
const mockUseAlternatePageUtils = createUseAlternatePageUtilsMock({
|
||||
siteConfig: {baseUrl: '/zh-Hans/', url: 'https://example.com'},
|
||||
i18n: {defaultLocale: 'en', currentLocale: 'zh-Hans'},
|
||||
});
|
||||
} as DocusaurusContext);
|
||||
expect(
|
||||
mockUseAlternatePageUtils('/zh-Hans/').createUrl({
|
||||
locale: 'en',
|
||||
|
@ -76,7 +76,7 @@ describe('useAlternatePageUtils', () => {
|
|||
const mockUseAlternatePageUtils = createUseAlternatePageUtilsMock({
|
||||
siteConfig: {baseUrl: '/base/', url: 'https://example.com'},
|
||||
i18n: {defaultLocale: 'en', currentLocale: 'en'},
|
||||
});
|
||||
} as DocusaurusContext);
|
||||
expect(
|
||||
mockUseAlternatePageUtils('/base/').createUrl({
|
||||
locale: 'zh-Hans',
|
||||
|
@ -101,7 +101,7 @@ describe('useAlternatePageUtils', () => {
|
|||
const mockUseAlternatePageUtils = createUseAlternatePageUtilsMock({
|
||||
siteConfig: {baseUrl: '/base/zh-Hans/', url: 'https://example.com'},
|
||||
i18n: {defaultLocale: 'en', currentLocale: 'zh-Hans'},
|
||||
});
|
||||
} as DocusaurusContext);
|
||||
expect(
|
||||
mockUseAlternatePageUtils('/base/zh-Hans/').createUrl({
|
||||
locale: 'en',
|
||||
|
|
|
@ -25,14 +25,14 @@ describe('useLocalPathname', () => {
|
|||
it('works for baseUrl: /', () => {
|
||||
const mockUseLocalPathname = createUseLocalPathnameMock({
|
||||
siteConfig: {baseUrl: '/'},
|
||||
});
|
||||
} as DocusaurusContext);
|
||||
expect(mockUseLocalPathname('/foo')).toBe('/foo');
|
||||
});
|
||||
|
||||
it('works for non-root baseUrl', () => {
|
||||
const mockUseLocalPathname = createUseLocalPathnameMock({
|
||||
siteConfig: {baseUrl: '/base/'},
|
||||
});
|
||||
} as DocusaurusContext);
|
||||
expect(mockUseLocalPathname('/base/foo')).toBe('/foo');
|
||||
});
|
||||
});
|
||||
|
|
|
@ -40,7 +40,7 @@ describe('usePluralForm', () => {
|
|||
.mockImplementation(() => {});
|
||||
expect(mockUsePluralForm().selectMessage(1, 'one|many')).toBe('one');
|
||||
expect(mockUsePluralForm().selectMessage(10, 'one|many')).toBe('one');
|
||||
expect(consoleMock.mock.calls[0][0]).toMatchInlineSnapshot(
|
||||
expect(consoleMock.mock.calls[0]![0]).toMatchInlineSnapshot(
|
||||
`"For locale=zh-Hans, a maximum of 1 plural forms are expected (other), but the message contains 2: one|many"`,
|
||||
);
|
||||
});
|
||||
|
@ -65,10 +65,11 @@ describe('usePluralForm', () => {
|
|||
.mockImplementation(() => {});
|
||||
const pluralMock = jest
|
||||
.spyOn(Intl, 'PluralRules')
|
||||
// @ts-expect-error: for testing when it doesn't exist
|
||||
.mockImplementation(() => undefined);
|
||||
expect(mockUsePluralForm().selectMessage(1, 'one|many')).toBe('one');
|
||||
expect(mockUsePluralForm().selectMessage(10, 'one|many')).toBe('many');
|
||||
expect(consoleMock.mock.calls[0][0]).toMatchInlineSnapshot(`
|
||||
expect(consoleMock.mock.calls[0]![0]).toMatchInlineSnapshot(`
|
||||
"Failed to use Intl.PluralRules for locale "zh-Hans".
|
||||
Docusaurus will fallback to the default (English) implementation.
|
||||
Error: pluralRules.resolvedOptions is not a function
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue