Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(gatsby-plugin-twitter): Add pluginOptionsSchema validation (#27601
) * chore(gatsby-plugin-twitter): Add pluginOptionsSchema validation * Update package.json Co-authored-by: Max Stoiber <contact@mxstbr.com>
- Loading branch information
1 parent
e19a1d7
commit bf6624b
Showing
3 changed files
with
29 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
packages/gatsby-plugin-twitter/src/__tests__/gatsby-node.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
exports.pluginOptionsSchema = ({ Joi }) => Joi.object({}) |