test: enable a few jest eslint rules (#6900)

* test: enable a few jest eslint rules

* more
This commit is contained in:
Joshua Chen 2022-03-12 08:43:09 +08:00 committed by GitHub
parent 1efc6c6091
commit aa5a2d4c04
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
155 changed files with 3644 additions and 3478 deletions

View file

@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`getTranslationFiles should return translation files matching snapshot 1`] = `
exports[`getTranslationFiles returns translation files matching snapshot 1`] = `
Array [
Object {
"content": Object {
@ -55,7 +55,7 @@ Array [
]
`;
exports[`getTranslationFiles should return translation files matching snapshot 2`] = `
exports[`getTranslationFiles returns translation files matching snapshot 2`] = `
Array [
Object {
"content": Object {
@ -98,7 +98,7 @@ Array [
]
`;
exports[`translateThemeConfig should return translated themeConfig matching snapshot 1`] = `
exports[`translateThemeConfig returns translated themeConfig 1`] = `
Object {
"announcementBar": Object {},
"colorMode": Object {},

View file

@ -79,7 +79,7 @@ function getSampleTranslationFilesTranslated(themeConfig: ThemeConfig) {
}
describe('getTranslationFiles', () => {
test('should return translation files matching snapshot', () => {
it('returns translation files matching snapshot', () => {
expect(getSampleTranslationFiles(ThemeConfigSample)).toMatchSnapshot();
expect(
getSampleTranslationFiles(ThemeConfigSampleSimpleFooter),
@ -88,7 +88,7 @@ describe('getTranslationFiles', () => {
});
describe('translateThemeConfig', () => {
test('should not translate anything if translation files are untranslated', () => {
it('does not translate anything if translation files are untranslated', () => {
expect(
translateThemeConfig({
themeConfig: ThemeConfigSample,
@ -97,7 +97,7 @@ describe('translateThemeConfig', () => {
).toEqual(ThemeConfigSample);
});
test('should return translated themeConfig matching snapshot', () => {
it('returns translated themeConfig', () => {
expect(
translateThemeConfig({
themeConfig: ThemeConfigSample,
@ -117,17 +117,17 @@ describe('getTranslationFiles and translateThemeConfig isomorphism', () => {
expect(translatedThemeConfig).toEqual(themeConfig);
}
test('should be verified for sample', () => {
it('is verified for sample', () => {
verifyIsomorphism(ThemeConfigSample);
});
test('should be verified for sample with simple footer', () => {
it('is verified for sample with simple footer', () => {
verifyIsomorphism(ThemeConfigSampleSimpleFooter);
});
// undefined footer should not make the translation code crash
// See https://github.com/facebook/docusaurus/issues/3936
test('should be verified for sample without footer', () => {
it('is verified for sample without footer', () => {
verifyIsomorphism({...ThemeConfigSample, footer: undefined});
});
});

View file

@ -29,7 +29,7 @@ function testOk(partialThemeConfig: Record<string, unknown>) {
}
describe('themeConfig', () => {
test('should accept valid theme config', () => {
it('accepts valid theme config', () => {
const userConfig = {
prism: {
theme,
@ -101,7 +101,7 @@ describe('themeConfig', () => {
});
});
test('should allow possible types of navbar items', () => {
it('allows possible types of navbar items', () => {
const config = {
navbar: {
items: [
@ -199,7 +199,7 @@ describe('themeConfig', () => {
});
});
test('should reject unknown navbar item type', () => {
it('rejects unknown navbar item type', () => {
const config = {
navbar: {
items: [
@ -216,7 +216,7 @@ describe('themeConfig', () => {
).toThrowErrorMatchingInlineSnapshot(`"Bad navbar item type joke"`);
});
test('should reject nested dropdowns', () => {
it('rejects nested dropdowns', () => {
const config = {
navbar: {
items: [
@ -243,7 +243,7 @@ describe('themeConfig', () => {
).toThrowErrorMatchingInlineSnapshot(`"Nested dropdowns are not allowed"`);
});
test('should reject nested dropdowns 2', () => {
it('rejects nested dropdowns 2', () => {
const config = {
navbar: {
items: [
@ -260,7 +260,7 @@ describe('themeConfig', () => {
).toThrowErrorMatchingInlineSnapshot(`"Nested dropdowns are not allowed"`);
});
test('should reject position attribute within dropdown', () => {
it('rejects position attribute within dropdown', () => {
const config = {
navbar: {
items: [
@ -285,7 +285,7 @@ describe('themeConfig', () => {
);
});
test('should give friendly error when href and to coexist', () => {
it('gives friendly error when href and to coexist', () => {
const config = {
navbar: {
items: [
@ -305,7 +305,7 @@ describe('themeConfig', () => {
);
});
test('should allow empty alt tags for the logo image in the header', () => {
it('allows empty alt tags for the logo image in the header', () => {
const altTagConfig = {
navbar: {
logo: {
@ -324,7 +324,7 @@ describe('themeConfig', () => {
});
});
test('should allow empty alt tags for the logo image in the footer', () => {
it('allows empty alt tags for the logo image in the footer', () => {
const partialConfig = {
footer: {
logo: {
@ -344,7 +344,7 @@ describe('themeConfig', () => {
});
});
test('should allow simple links in footer', () => {
it('allows simple links in footer', () => {
const partialConfig = {
footer: {
links: [
@ -378,7 +378,7 @@ describe('themeConfig', () => {
});
});
test('should allow footer column with no title', () => {
it('allows footer column with no title', () => {
const partialConfig = {
footer: {
links: [
@ -414,7 +414,7 @@ describe('themeConfig', () => {
});
});
test('should reject mix of simple and multi-column links in footer', () => {
it('rejects mix of simple and multi-column links in footer', () => {
const partialConfig = {
footer: {
links: [
@ -442,7 +442,7 @@ describe('themeConfig', () => {
);
});
test('should allow width and height specification for logo', () => {
it('allows width and height specification for logo', () => {
const altTagConfig = {
navbar: {
logo: {
@ -463,7 +463,7 @@ describe('themeConfig', () => {
});
});
test('should accept valid prism config', () => {
it('accepts valid prism config', () => {
const prismConfig = {
prism: {
additionalLanguages: ['kotlin', 'java'],
@ -476,25 +476,25 @@ describe('themeConfig', () => {
});
describe('customCss config', () => {
test('should accept customCss undefined', () => {
it('accepts customCss undefined', () => {
testOk({
customCss: undefined,
});
});
test('should accept customCss string', () => {
it('accepts customCss string', () => {
testOk({
customCss: './path/to/cssFile.css',
});
});
test('should accept customCss string array', () => {
it('accepts customCss string array', () => {
testOk({
customCss: ['./path/to/cssFile.css', './path/to/cssFile2.css'],
});
});
test('should reject customCss number', () => {
it('rejects customCss number', () => {
expect(() =>
testValidateThemeConfig({
customCss: 42,
@ -509,7 +509,7 @@ describe('themeConfig', () => {
const withDefaultValues = (colorMode) =>
_.merge({}, DEFAULT_CONFIG.colorMode, colorMode);
test('switch config', () => {
it('switch config', () => {
const colorMode = {
switchConfig: {
darkIcon: '🌙',
@ -522,7 +522,7 @@ describe('themeConfig', () => {
);
});
test('max config', () => {
it('max config', () => {
const colorMode = {
defaultMode: 'dark',
disableSwitch: false,
@ -534,7 +534,7 @@ describe('themeConfig', () => {
});
});
test('undefined config', () => {
it('undefined config', () => {
const colorMode = undefined;
expect(testValidateThemeConfig({colorMode})).toEqual({
...DEFAULT_CONFIG,
@ -542,7 +542,7 @@ describe('themeConfig', () => {
});
});
test('empty config', () => {
it('empty config', () => {
const colorMode = {};
expect(testValidateThemeConfig({colorMode})).toEqual({
...DEFAULT_CONFIG,
@ -553,132 +553,132 @@ describe('themeConfig', () => {
});
});
});
});
describe('themeConfig tableOfContents', () => {
test('toc undefined', () => {
const tableOfContents = undefined;
expect(testValidateThemeConfig({tableOfContents})).toEqual({
...DEFAULT_CONFIG,
tableOfContents: {
minHeadingLevel: DEFAULT_CONFIG.tableOfContents.minHeadingLevel,
maxHeadingLevel: DEFAULT_CONFIG.tableOfContents.maxHeadingLevel,
},
describe('tableOfContents', () => {
it('accepts undefined', () => {
const tableOfContents = undefined;
expect(testValidateThemeConfig({tableOfContents})).toEqual({
...DEFAULT_CONFIG,
tableOfContents: {
minHeadingLevel: DEFAULT_CONFIG.tableOfContents.minHeadingLevel,
maxHeadingLevel: DEFAULT_CONFIG.tableOfContents.maxHeadingLevel,
},
});
});
});
test('toc empty', () => {
const tableOfContents = {};
expect(testValidateThemeConfig({tableOfContents})).toEqual({
...DEFAULT_CONFIG,
tableOfContents: {
minHeadingLevel: DEFAULT_CONFIG.tableOfContents.minHeadingLevel,
maxHeadingLevel: DEFAULT_CONFIG.tableOfContents.maxHeadingLevel,
},
it('accepts empty', () => {
const tableOfContents = {};
expect(testValidateThemeConfig({tableOfContents})).toEqual({
...DEFAULT_CONFIG,
tableOfContents: {
minHeadingLevel: DEFAULT_CONFIG.tableOfContents.minHeadingLevel,
maxHeadingLevel: DEFAULT_CONFIG.tableOfContents.maxHeadingLevel,
},
});
});
});
test('toc with min', () => {
const tableOfContents = {
minHeadingLevel: 3,
};
expect(testValidateThemeConfig({tableOfContents})).toEqual({
...DEFAULT_CONFIG,
tableOfContents: {
it('accepts min', () => {
const tableOfContents = {
minHeadingLevel: 3,
maxHeadingLevel: DEFAULT_CONFIG.tableOfContents.maxHeadingLevel,
},
};
expect(testValidateThemeConfig({tableOfContents})).toEqual({
...DEFAULT_CONFIG,
tableOfContents: {
minHeadingLevel: 3,
maxHeadingLevel: DEFAULT_CONFIG.tableOfContents.maxHeadingLevel,
},
});
});
});
test('toc with max', () => {
const tableOfContents = {
maxHeadingLevel: 5,
};
expect(testValidateThemeConfig({tableOfContents})).toEqual({
...DEFAULT_CONFIG,
tableOfContents: {
minHeadingLevel: DEFAULT_CONFIG.tableOfContents.minHeadingLevel,
it('accepts max', () => {
const tableOfContents = {
maxHeadingLevel: 5,
},
};
expect(testValidateThemeConfig({tableOfContents})).toEqual({
...DEFAULT_CONFIG,
tableOfContents: {
minHeadingLevel: DEFAULT_CONFIG.tableOfContents.minHeadingLevel,
maxHeadingLevel: 5,
},
});
});
});
test('toc with min 2.5', () => {
const tableOfContents = {
minHeadingLevel: 2.5,
};
expect(() =>
testValidateThemeConfig({tableOfContents}),
).toThrowErrorMatchingInlineSnapshot(
`"\\"tableOfContents.minHeadingLevel\\" must be an integer"`,
);
});
it('rejects min 2.5', () => {
const tableOfContents = {
minHeadingLevel: 2.5,
};
expect(() =>
testValidateThemeConfig({tableOfContents}),
).toThrowErrorMatchingInlineSnapshot(
`"\\"tableOfContents.minHeadingLevel\\" must be an integer"`,
);
});
test('toc with max 2.5', () => {
const tableOfContents = {
maxHeadingLevel: 2.5,
};
expect(() =>
testValidateThemeConfig({tableOfContents}),
).toThrowErrorMatchingInlineSnapshot(
`"\\"tableOfContents.maxHeadingLevel\\" must be an integer"`,
);
});
it('rejects max 2.5', () => {
const tableOfContents = {
maxHeadingLevel: 2.5,
};
expect(() =>
testValidateThemeConfig({tableOfContents}),
).toThrowErrorMatchingInlineSnapshot(
`"\\"tableOfContents.maxHeadingLevel\\" must be an integer"`,
);
});
test('toc with min 1', () => {
const tableOfContents = {
minHeadingLevel: 1,
};
expect(() =>
testValidateThemeConfig({tableOfContents}),
).toThrowErrorMatchingInlineSnapshot(
`"\\"tableOfContents.minHeadingLevel\\" must be greater than or equal to 2"`,
);
});
it('rejects min 1', () => {
const tableOfContents = {
minHeadingLevel: 1,
};
expect(() =>
testValidateThemeConfig({tableOfContents}),
).toThrowErrorMatchingInlineSnapshot(
`"\\"tableOfContents.minHeadingLevel\\" must be greater than or equal to 2"`,
);
});
test('toc with min 7', () => {
const tableOfContents = {
minHeadingLevel: 7,
};
expect(() =>
testValidateThemeConfig({tableOfContents}),
).toThrowErrorMatchingInlineSnapshot(
`"\\"tableOfContents.minHeadingLevel\\" must be less than or equal to ref:maxHeadingLevel"`,
);
});
it('rejects min 7', () => {
const tableOfContents = {
minHeadingLevel: 7,
};
expect(() =>
testValidateThemeConfig({tableOfContents}),
).toThrowErrorMatchingInlineSnapshot(
`"\\"tableOfContents.minHeadingLevel\\" must be less than or equal to ref:maxHeadingLevel"`,
);
});
test('toc with max 1', () => {
const tableOfContents = {
maxHeadingLevel: 1,
};
expect(() =>
testValidateThemeConfig({tableOfContents}),
).toThrowErrorMatchingInlineSnapshot(
`"\\"tableOfContents.maxHeadingLevel\\" must be greater than or equal to 2"`,
);
});
it('rejects max 1', () => {
const tableOfContents = {
maxHeadingLevel: 1,
};
expect(() =>
testValidateThemeConfig({tableOfContents}),
).toThrowErrorMatchingInlineSnapshot(
`"\\"tableOfContents.maxHeadingLevel\\" must be greater than or equal to 2"`,
);
});
test('toc with max 7', () => {
const tableOfContents = {
maxHeadingLevel: 7,
};
expect(() =>
testValidateThemeConfig({tableOfContents}),
).toThrowErrorMatchingInlineSnapshot(
`"\\"tableOfContents.maxHeadingLevel\\" must be less than or equal to 6"`,
);
});
it('rejects max 7', () => {
const tableOfContents = {
maxHeadingLevel: 7,
};
expect(() =>
testValidateThemeConfig({tableOfContents}),
).toThrowErrorMatchingInlineSnapshot(
`"\\"tableOfContents.maxHeadingLevel\\" must be less than or equal to 6"`,
);
});
test('toc with bad min 5 + max 3', () => {
const tableOfContents = {
minHeadingLevel: 5,
maxHeadingLevel: 3,
};
expect(() =>
testValidateThemeConfig({tableOfContents}),
).toThrowErrorMatchingInlineSnapshot(
`"\\"tableOfContents.minHeadingLevel\\" must be less than or equal to ref:maxHeadingLevel"`,
);
it('rejects min 5 + max 3', () => {
const tableOfContents = {
minHeadingLevel: 5,
maxHeadingLevel: 3,
};
expect(() =>
testValidateThemeConfig({tableOfContents}),
).toThrowErrorMatchingInlineSnapshot(
`"\\"tableOfContents.minHeadingLevel\\" must be less than or equal to ref:maxHeadingLevel"`,
);
});
});
});

View file

@ -15,7 +15,7 @@ import {
} from '@docusaurus/theme-common';
describe('Tabs', () => {
test('Should reject bad Tabs child', () => {
it('rejects bad Tabs child', () => {
expect(() => {
renderer.create(
<Tabs>
@ -27,7 +27,7 @@ describe('Tabs', () => {
`"Docusaurus error: Bad <Tabs> child <div>: all children of the <Tabs> component should be <TabItem>, and every <TabItem> should have a unique \\"value\\" prop."`,
);
});
test('Should reject bad Tabs defaultValue', () => {
it('rejects bad Tabs defaultValue', () => {
expect(() => {
renderer.create(
<Tabs defaultValue="bad">
@ -39,7 +39,7 @@ describe('Tabs', () => {
`"Docusaurus error: The <Tabs> has a defaultValue \\"bad\\" but none of its children has the corresponding value. Available values are: v1, v2. If you intend to show no default tab, use defaultValue={null} instead."`,
);
});
test('Should reject duplicate values', () => {
it('rejects duplicate values', () => {
expect(() => {
renderer.create(
<Tabs>
@ -55,7 +55,7 @@ describe('Tabs', () => {
`"Docusaurus error: Duplicate values \\"v1, v2\\" found in <Tabs>. Every value needs to be unique."`,
);
});
test('Should accept valid Tabs config', () => {
it('accepts valid Tabs config', () => {
expect(() => {
renderer.create(
<ScrollControllerProvider>
@ -110,7 +110,7 @@ describe('Tabs', () => {
}).not.toThrow(); // TODO Better Jest infrastructure to mock the Layout
});
// https://github.com/facebook/docusaurus/issues/5729
test('Should accept dynamic Tabs with number values', () => {
it('accepts dynamic Tabs with number values', () => {
expect(() => {
const tabs = ['Apple', 'Banana', 'Carrot'];
renderer.create(