test(v2): test different type of sidebar item

This commit is contained in:
endiliey 2019-05-15 19:16:28 +08:00
parent f47059b5bd
commit badb067b4b
5 changed files with 58 additions and 8 deletions

View file

@ -0,0 +1,14 @@
{
"docs": {
"Test": [
"foo/bar",
"foo/baz",
{
"type": "superman"
}
],
"Guides": [
"hello"
]
}
}

View file

@ -2,7 +2,16 @@
"docs": {
"Test": [
"foo/bar",
"foo/baz"
"foo/baz",
{
"type": "link",
"label": "Github",
"href": "https://github.com"
},
{
"type": "ref",
"id": "hello"
}
],
"Guides": [
"hello"

View file

@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`loadSidebars normal site with sidebars 1`] = `
exports[`loadSidebars sidebars with known sidebar item type 1`] = `
Object {
"docs": Array [
Object {
@ -13,6 +13,15 @@ Object {
"id": "foo/baz",
"type": "doc",
},
Object {
"href": "https://github.com",
"label": "Github",
"type": "link",
},
Object {
"id": "hello",
"type": "ref",
},
],
"label": "Test",
"type": "category",
@ -30,5 +39,3 @@ Object {
],
}
`;
exports[`loadSidebars site without sidebars 1`] = `Object {}`;

View file

@ -11,7 +11,7 @@ import loadSidebars from '../sidebars';
/* eslint-disable global-require, import/no-dynamic-require */
describe('loadSidebars', () => {
test('normal site with sidebars', async () => {
test('sidebars with known sidebar item type', async () => {
const sidebarPath = path.join(
__dirname,
'__fixtures__',
@ -22,8 +22,20 @@ describe('loadSidebars', () => {
expect(result).toMatchSnapshot();
});
test('site without sidebars', () => {
test('sidebars with unknown sidebar item type', async () => {
const sidebarPath = path.join(
__dirname,
'__fixtures__',
'website',
'bad-sidebars.json',
);
expect(() => loadSidebars(sidebarPath)).toThrowErrorMatchingInlineSnapshot(
`"Unknown sidebar item type: superman"`,
);
});
test('no sidebars', () => {
const result = loadSidebars(null);
expect(result).toMatchSnapshot();
expect(result).toEqual({});
});
});