You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
EDIT: The above code actually works and it fails with error A11yError: 1 Accessibility issues found as expected. But once I add afterEach to my jest test, it stops failing and shows no accessibility issues.
This below code doesn't throw error as expected but shows as all passed.
import{createElement}from'lwc';importHelloWorldfrom'c/helloWorld';import{setup}from'@sa11y/jest';describe('c-hello-world',()=>{beforeAll(()=>{setup();});afterEach(()=>{// The jsdom instance is shared across test cases in a single file so reset the DOMwhile(document.body.firstChild){document.body.removeChild(document.body.firstChild);}// Prevent data saved on mocks from leaking between testsjest.clearAllMocks();});it('duplicate access keys',async()=>{constelement=createElement('c-hello-world',{is: HelloWorld});document.body.appendChild(element);awaitexpect(element.shadowRoot.querySelectorAll('a').length).toBe(2);awaitexpect(element.shadowRoot.querySelector('a')).toBeAccessible();});});
Why afterEach method is causing sa11y to not work as expected?
The text was updated successfully, but these errors were encountered:
@mohanraj-r Thanks for looking into it.
My initial post had an error and now I updated it.
If I remove afterEach method from my jest test, it fails as expected. But once I add afterEach to my jest test, it stops doing real accessibility test.
@sfdcale Not sure .. if you are using automatic checks then you can use cleanupAfterEach as described in https://github.com/salesforce/sa11y/tree/master/packages/jest#limitations
But when calling API directly not sure why aftereach cleanup would change the a11y results.
You can try moving the cleanup to beforeeach and check if it helps - or try using the cleanupAfterEach with sa11y opts (you can set runAfterEach: false if you don't want automatic checks but want just the cleanup)
I have a simple LWC(c-hello-world) as below:
and my jest test looks like below:
Surprisingly, this doesn't fail. I was expecting it to fail as per preset rule accessKeys mentioned here.
What is wrong with my test?
Node version: v14.19.3
@sa11y/jest: 3.1.0
@salesforce/sfdx-lwc-jest: 1.1.0
OS: macOS Monterey
EDIT: The above code actually works and it fails with error A11yError: 1 Accessibility issues found as expected. But once I add
afterEach
to my jest test, it stops failing and shows no accessibility issues.This below code doesn't throw error as expected but shows as all passed.
Why
afterEach
method is causing sa11y to not work as expected?The text was updated successfully, but these errors were encountered: