Skip to content

Commit

Permalink
Change after-build-package tests to look at all objects
Browse files Browse the repository at this point in the history
The way the previous tests were structured seemed to test for the presence of at least one single object within the component options with the required attributes, instead of all options having the correct attributes. The same was happening for the fixtures file.

This meant that one missing `required` attribute in a component yaml file would not cause the test to fail.

This commit tests for the presence of the required attributes by looping through each option/fixture. It also fixes one typo picked up by these new tests.
  • Loading branch information
Vanita Barrett committed Oct 9, 2020
1 parent 5eb6eb5 commit d52f62f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/govuk/components/input/input.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ params:
description: Type of input control to render. Defaults to "text".
- name: inputmode
type: string
require: false
required: false
description: Optional value for [inputmode](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/inputmode).
- name: value
type: string
Expand Down
28 changes: 17 additions & 11 deletions tasks/gulp/__tests__/after-build-package.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,17 +107,19 @@ describe('package/', () => {
return readFile(filePath, 'utf8')
.then((data) => {
var parsedData = JSON.parse(data)

// We expect the component JSON to contain "name", "type", "required", "description"
expect(parsedData).toEqual(
expect.arrayContaining([
expect(parsedData).toBeInstanceOf(Array)
parsedData.forEach((option) => {
expect(option).toEqual(
expect.objectContaining({
name: expect.any(String),
type: expect.any(String),
required: expect.any(Boolean),
description: expect.any(String)
})
])
)
)
})
})
.catch(error => {
throw error
Expand All @@ -135,15 +137,19 @@ describe('package/', () => {
expect(parsedData).toEqual(
expect.objectContaining({
component: name,
fixtures: expect.arrayContaining([
expect.objectContaining({
name: expect.any(String),
options: expect.any(Object),
html: expect.any(String)
})
])
fixtures: expect.any(Object)
})
)

parsedData.fixtures.forEach((fixture) => {
expect(fixture).toEqual(
expect.objectContaining({
name: expect.any(String),
options: expect.any(Object),
html: expect.any(String)
})
)
})
})
.catch(error => {
throw error
Expand Down

0 comments on commit d52f62f

Please sign in to comment.