Skip to content

Commit

Permalink
chore(gatsby-plugin-twitter): Add pluginOptionsSchema validation
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelDeBoey committed Nov 9, 2020
1 parent ae2c3da commit bd1cea3
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
3 changes: 2 additions & 1 deletion packages/gatsby-plugin-twitter/package.json
Expand Up @@ -13,7 +13,8 @@
"@babel/cli": "^7.11.6",
"@babel/core": "^7.11.6",
"babel-preset-gatsby-package": "^0.6.0-next.0",
"cross-env": "^7.0.2"
"cross-env": "^7.0.2",
"gatsby-plugin-utils": "^0.3.0-next.0"
},
"homepage": "https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-plugin-twitter#readme",
"keywords": [
Expand Down
26 changes: 26 additions & 0 deletions packages/gatsby-plugin-twitter/src/__tests__/gatsby-node.js
@@ -0,0 +1,26 @@
import { testPluginOptionsSchema } from "gatsby-plugin-utils"

import { pluginOptionsSchema } from "../gatsby-node"

it(`should provide meaningful errors when fields are invalid`, async () => {
const expectedErrors = [`"optionA" is not allowed`]

const { errors } = await testPluginOptionsSchema(pluginOptionsSchema, {
optionA: `This options shouldn't exist`,
})

expect(errors).toEqual(expectedErrors)
})

it.each`
options
${undefined}
${{}}
`(`should validate the schema: $options`, async ({ options }) => {
const { isValid } = await testPluginOptionsSchema(
pluginOptionsSchema,
options
)

expect(isValid).toBe(true)
})
1 change: 1 addition & 0 deletions packages/gatsby-plugin-twitter/src/gatsby-node.js
@@ -0,0 +1 @@
exports.pluginOptionsSchema = ({ Joi }) => Joi.object({})

0 comments on commit bd1cea3

Please sign in to comment.