test: improve test coverage (#7181)

This commit is contained in:
Joshua Chen 2022-04-16 16:35:40 +08:00 committed by GitHub
parent 44966e19e9
commit f219a2ac90
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 48 additions and 14 deletions

View file

@ -132,5 +132,10 @@ describe('<Interpolate>', () => {
).toThrowErrorMatchingInlineSnapshot(
`"The Docusaurus <Interpolate> component only accept simple string values. Received: React element"`,
);
expect(() =>
renderer.create(<Interpolate>{null}</Interpolate>),
).toThrowErrorMatchingInlineSnapshot(
`"The Docusaurus <Interpolate> component only accept simple string values. Received: object"`,
);
});
});

View file

@ -63,6 +63,20 @@ exports[`loadPlugins loads plugins 1`] = `
},
},
],
"pluginsRouteConfigs": [],
"pluginsRouteConfigs": [
{
"component": "Comp",
"context": {
"data": {
"content": "path",
},
"plugin": "<PROJECT_ROOT>/packages/docusaurus/src/server/plugins/__tests__/__fixtures__/site-with-plugin/.docusaurus/test1/default/plugin-route-context-module-100.json",
},
"modules": {
"content": "path",
},
"path": "foo/",
},
],
}
`;

View file

@ -31,6 +31,12 @@ describe('loadPlugins', () => {
return this.prop;
},
async contentLoaded({content, actions}) {
actions.addRoute({
path: 'foo',
component: 'Comp',
modules: {content: 'path'},
context: {content: 'path'},
});
actions.setGlobalData({content, prop: this.prop});
},
}),

View file

@ -129,6 +129,9 @@ describe('loadPresets', () => {
path.join(__dirname, '__fixtures__/presets/preset-plugins.js'),
{docs: {path: '../'}},
],
false,
null,
undefined,
path.join(__dirname, '__fixtures__/presets/preset-themes.js'),
path.join(__dirname, '__fixtures__/presets/preset-mixed.js'),
],

View file

@ -272,9 +272,8 @@ ${JSON.stringify(routeConfig)}`,
res.routesChunkNames[`${routePath}-${routeHash}`] = {
// Avoid clash with a prop called "component"
...genChunkNames({__comp: component}, 'component', component, res),
...(context
? genChunkNames({__context: context}, 'context', routePath, res)
: {}),
...(context &&
genChunkNames({__context: context}, 'context', routePath, res)),
...genChunkNames(modules, 'module', routePath, res),
};