I'm a fan of Open Source and have a growing interest in serverless and edge computing. I'm not a big fan of spiders, but they're doing good work eating bugs. I also stream on Twitch.
Thanks for sharing your tips, Nick.
Sorry, I am still pretty new to jest, so what you suggest here is - I can make
import{axe,toHaveNoViolations}from'jest-axe';
As default in every test in the app, so I don't need to import it one by one, or you mean I don't need to the whole test at all?
test('should have no accessiblity violations',async()=>{const{container}=render(<App/>);constresults=awaitaxe(container);expect(results).toHaveNoViolations();});
I'm a fan of Open Source and have a growing interest in serverless and edge computing. I'm not a big fan of spiders, but they're doing good work eating bugs. I also stream on Twitch.
You would still need to import axe, but that's it, i.e.
import{axe}from'jest-axe';
And in your test, things would stay the same. i.e.
test('should have no accessiblity violations',async()=>{const{container}=render(<App/>);constresults=awaitaxe(container);expect(results).toHaveNoViolations();});
It's a small change, but it saves importing it in every file that requires a11y checks.
Looking forward to your next post!
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Just an FYI. You can add the axe
toHaveNoViolations
matcher globally so you don’t have to import it in your tests. See github.com/thepracticaldev/dev.to/... for an example of this. Then just reference it in your jest config, e.g. github.com/thepracticaldev/dev.to/...Looking forward to your next post!
Thanks for sharing your tips, Nick.
Sorry, I am still pretty new to jest, so what you suggest here is - I can make
As default in every test in the app, so I don't need to import it one by one, or you mean I don't need to the whole test at all?
You would still need to import
axe
, but that's it, i.e.And in your test, things would stay the same. i.e.
It's a small change, but it saves importing it in every file that requires a11y checks.
Looking forward to your next post!