Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -330,24 +330,40 @@ describe('headTags', () => {
).not.toThrow();
});

it("throws error if headTags doesn't have string attributes", () => {
it('throws error if headTags has invalid attribute values', () => {
expect(() => {
normalizeConfig({
headTags: [
{
tagName: 'link',
attributes: {
rel: false,
rel: 123,
href: 'img/docusaurus.png',
},
},
],
});
}).toThrowErrorMatchingInlineSnapshot(`
[Error: "headTags[0].attributes.rel" must be a string
[Error: "headTags[0].attributes.rel" must be one of [string, boolean]
]
`);
});

it('accepts headTags with boolean attributes', () => {
expect(() => {
normalizeConfig({
headTags: [
{
tagName: 'script',
attributes: {
src: '/analytics.js',
async: true,
},
},
],
});
}).not.toThrow();
});
});

describe('css', () => {
Expand Down
5 changes: 4 additions & 1 deletion packages/docusaurus/src/server/configValidation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,10 @@ export const ConfigSchema = Joi.object<DocusaurusConfig>({
is: Joi.valid(true),
then: Joi.optional(),
otherwise: Joi.object()
.pattern(/[\w-]+/, Joi.string())
.pattern(
/[\w-]+/,
Joi.alternatives().try(Joi.string(), Joi.boolean()),
)
.required(),
}),
customElement: Joi.bool().default(false),
Expand Down
Loading