fix(content-docs): improve sidebar shorthand normalization error message (#6745)

This commit is contained in:
Joshua Chen 2022-02-23 20:03:58 +08:00 committed by GitHub
parent 9562a5d203
commit 2d93750caf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 74 additions and 25 deletions

View file

@ -58,7 +58,7 @@ describe('loadSidebars', () => {
await expect(() =>
loadSidebars(sidebarPath, params),
).rejects.toThrowErrorMatchingInlineSnapshot(
`"Invalid category {\\"type\\":\\"category\\",\\"label\\":\\"Category Label\\",\\"items\\":\\"doc1\\"}: items must be an array of sidebar items or a category shorthand"`,
`"Invalid sidebar items collection \`\\"doc1\\"\` in \`items\` of the category Category Label: it must either be an array of sidebar items or a shorthand notation (which doesn't contain a \`type\` property). See https://docusaurus.io/docs/sidebar/items for all valid syntaxes."`,
);
});

View file

@ -37,4 +37,53 @@ describe('normalization', () => {
}),
).toMatchSnapshot();
});
test('rejects some invalid cases', () => {
expect(() =>
normalizeSidebars({
sidebar: {
Category: {type: 'autogenerated', dirName: 'foo'},
Category2: {type: 'autogenerated', dirName: 'bar'},
},
}),
).toThrowErrorMatchingInlineSnapshot(
`"Invalid sidebar items collection \`{\\"type\\":\\"autogenerated\\",\\"dirName\\":\\"foo\\"}\` in \`items\` of the category Category: it must either be an array of sidebar items or a shorthand notation (which doesn't contain a \`type\` property). See https://docusaurus.io/docs/sidebar/items for all valid syntaxes."`,
);
expect(() =>
normalizeSidebars({
sidebar: [
'foo',
{
Category: {
type: 'category',
items: ['bar', 'baz'],
},
},
],
}),
).toThrowErrorMatchingInlineSnapshot(
`"Invalid sidebar items collection \`{\\"type\\":\\"category\\",\\"items\\":[\\"bar\\",\\"baz\\"]}\` in \`items\` of the category Category: it must either be an array of sidebar items or a shorthand notation (which doesn't contain a \`type\` property). See https://docusaurus.io/docs/sidebar/items for all valid syntaxes."`,
);
expect(() =>
normalizeSidebars({
sidebar: [
'foo',
{
Category: 'bar',
},
],
}),
).toThrowErrorMatchingInlineSnapshot(
`"Invalid sidebar items collection \`\\"bar\\"\` in \`items\` of the category Category: it must either be an array of sidebar items or a shorthand notation (which doesn't contain a \`type\` property). See https://docusaurus.io/docs/sidebar/items for all valid syntaxes."`,
);
expect(() =>
normalizeSidebars({
sidebar: 'item',
}),
).toThrowErrorMatchingInlineSnapshot(
`"Invalid sidebar items collection \`\\"item\\"\` in sidebar sidebar: it must either be an array of sidebar items or a shorthand notation (which doesn't contain a \`type\` property). See https://docusaurus.io/docs/sidebar/items for all valid syntaxes."`,
);
});
});