Skip to content

Commit

Permalink
test: add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
DSchau committed Sep 19, 2019
1 parent f0ef733 commit 870def4
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 5 deletions.
45 changes: 41 additions & 4 deletions packages/gatsby/src/utils/__tests__/validate-plugin-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,37 @@ describe(`validating plugin options`, () => {
})
})

describe(`plugin validation`, () => {
test.each([
[
`validates string shape`,
[`gatsby-plugin-react-helmet`, `gatsby-plugin-yolo`],
],
[
`validates object shape`,
[
{
resolve: `gatsby-plugin-remark`,
options: {
plugins: [],
},
},
],
],
])(`%p`, (_, plugins) => {
expect(
validatePluginOptions(schema, {
...defaultOpts,
plugins,
})
).resolves.toEqual(
expect.objectContaining({
plugins,
})
)
})
})

it(`does not bail on first error`, async () => {
try {
await validatePluginOptions(schema, {})
Expand All @@ -37,11 +68,17 @@ describe(`validating plugin options`, () => {
}
})

it(`does not bail on unknown keys`, () => {
it(`bails on unknown keys`, async () => {
const extra = { d: `d` }
expect(
validatePluginOptions(schema, { ...defaultOpts, ...extra })
).resolves.toEqual(expect.objectContaining(extra))
try {
await validatePluginOptions(schema, { ...defaultOpts, ...extra })
} catch (e) {
expect(e.details[0].message).toEqual(
expect.stringContaining(`is not allowed`)
)
} finally {
expect.hasAssertions()
}
})
})
})
Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby/src/utils/validate-plugin-options.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const Joi = require(`@hapi/joi`)

const baseSchema = Joi.object().keys({
plugins: Joi.array(
plugins: Joi.array().items(
Joi.alternatives(
Joi.string(),
Joi.object().keys({
Expand Down

0 comments on commit 870def4

Please sign in to comment.