Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for the govuk-font mixin #2474

Merged
merged 2 commits into from
Dec 22, 2021
Merged

Add tests for the govuk-font mixin #2474

merged 2 commits into from
Dec 22, 2021

Conversation

36degrees
Copy link
Contributor

I noticed when looking into #2456 that we had no test coverage for the govuk-font mixin. The govuk-font mixin does quite a lot of things – most of it handing off to the other mixins in this file – but does have responsibility for setting up things like tabular numbers.

Add tests to try and cover all of the execution paths within the mixin.

@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-pr-2474 December 13, 2021 17:30 Inactive

const results = await renderSass({ data: sass, ...sassConfig })

expect(results.css.toString().trim()).toBe(outdent`
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is basically a 'snapshot test', but I couldn't think of a better way of doing it… this does mean that whenever anything changes in the govuk-font mixin we'll need to update this test accordingly. It's not ideal, but I think that's OK?

Comment on lines +499 to +500
expect(results.css.toString()).toContain('font-size: 12px')
expect(results.css.toString()).not.toContain('font-size: 14px')
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels a little clunky, but because $size: 14 also outputs font-size: 12px (for mobile) it'd pass anyway… suggestions welcome.

Comment on lines +464 to +470
expect(css).toContain('font-feature-settings: "tnum" 1;')
expect(css).toContain(outdent`
${outdent}
@supports (font-variant-numeric: tabular-nums) {
.foo {
font-feature-settings: normal;
font-variant-numeric: tabular-nums; } }`)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thought it was worth testing for both of these, but not worth writing individual tests for them.

expect(results.css.toString()).toContain('font-weight: 700')
})

it('does not output font-weight if $weight: false', async () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@36degrees do you think it's worth having a test for an unrecognised $weight?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, good question… at the minute it'll basically ignore $weight if it's not regularorbold. What would the assertion be for that test? Just check that the output does not contain font-weight`?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think so, yep. If that's the behaviour we want to keep!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-pr-2474 December 21, 2021 17:04 Inactive
@36degrees 36degrees merged commit df937b8 into main Dec 22, 2021
@36degrees 36degrees deleted the govuk-font-mixin-tests branch December 22, 2021 09:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

Successfully merging this pull request may close these issues.

3 participants