Skip to content

Commit 894a6fa

Browse files
committed
Log remaining govuk-<SOMETHING>() calls when test fails
The test detecting if any `govuk-<SOMETHING>()` calls make it to the CSS output was only telling you a function made it through (likely through a typo). That's very little information to go by for finding why that function made it through. This new test checks the length of the regex matches, allowing Jest to output the list of matches if the test fails: ``` Expected length: 0 Received length: 1 Received array: [["govuk-color(\"black\")"]] ```
1 parent 8c3d57f commit 894a6fa

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

packages/govuk-frontend/src/govuk/all.unit.test.mjs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,12 @@ describe('GOV.UK Frontend', () => {
9494
it('does not contain any unexpected govuk- function calls', async () => {
9595
const sass = '@import "index"'
9696

97-
await expect(compileSassString(sass)).resolves.toMatchObject({
98-
css: expect.not.stringMatching(/_?govuk-[\w-]+\(.*?\)/g)
99-
})
97+
const { css } = await compileSassString(sass)
98+
const matches = css.matchAll(/_?govuk-[\w-]+\(.*?\)/g)
99+
100+
// `matchAll` does not return an actual `Array` so we need
101+
// a little conversion before we can check its length
102+
expect(Array.from(matches)).toHaveLength(0)
100103
})
101104

102105
describe('Sass documentation', () => {

0 commit comments

Comments
 (0)