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

fix(node): Add comments explaining value of the jest boilerplate #1950

Merged
merged 4 commits into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions accessibility-checker/boilerplates/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ of "Hello World" for different test framework environments. The boilerplates
are:

* [cucumber-selenium](cucumber-selenium): Using [Cucumber](https://www.npmjs.com/package/cucumber) with a [Selenium-webdriver](https://www.npmjs.com/package/selenium-webdriver) browser
* [jest](jest): Using a [Jest](https://www.npmjs.com/package/jest) test environment
* [jest](jest): Using a [Jest](https://www.npmjs.com/package/jest) test environment with a baseline
* [jest-selenium](jest-selenium): Using a [Jest](https://www.npmjs.com/package/jest) test environment with a [Selenium-webdriver](https://www.npmjs.com/package/selenium-webdriver) browser
* [mocha-selenium](mocha-selenium): Using a [Mocha](https://www.npmjs.com/package/mocha) test environment with a [Selenium-webdriver](https://www.npmjs.com/package/selenium-webdriver) browser
* [protractor](protractor): Using a [Protractor](https://www.npmjs.com/package/protractor) test environment
* [webdriverio](webdriverio): Using a [Webdriverio](https://www.npmjs.com/package/webdriverio) test environment
* [webdriverio](webdriverio): Using a [Webdriverio](https://www.npmjs.com/package/webdriverio) test environment
23 changes: 23 additions & 0 deletions accessibility-checker/boilerplates/jest/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# jest

This folder covers "baseline basics".

We have two tests - one referencing a baseline (stored at `baselines/IMG_BASELINE.json`) and one that does not.

A scan was run previously that detected an issue. That scan was saved as a baseline. The checker will ignore issues stored in the baseline. This feature allows a team to snapshot where they're at to prevent new issues from being introduced. This also allows a team to fail on potential violations, but then store items in the baseline that they've assessed and determined were being addressed in some way.

When you `npm install` and `npm test` in this folder, you should expect to see one test fail and one test pass.

At the time of this commit, if you look at the results for `Image missing alt without Baseline` you will see a failure including:

```
- Message: The image has neither an accessible name nor is marked as decorative or redundant
Level: violation
XPath: /html[1]/body[1]/div[1]/img[1]
Snippet: <img src="hello.png">
Help: https://able.ibm.com/rules/archives/2024.06.17/doc/en-US/img_alt_valid.html#%7B%22message%22%3A%22The%20image%20has%20neither%20an%20accessible%20name%20nor%20is%20marked%20as%20decorative%20or%20redundant%22%2C%22snippet%22%3A%22%3Cimg%20src%3D%5C%22hello.png%5C%22%3E%22%2C%22value%22%3A%5B%22VIOLATION%22%2C%22FAIL%22%5D%2C%22reasonId%22%3A%22fail_no_alt%22%2C%22ruleId%22%3A%22img_alt_valid%22%2C%22msgArgs%22%3A%5B%5D%7D
```

We can then add to the `document.body.innerHTML` in that test, following the linked `help` above, to remove the violation. In this example, a simple way is to add an appopriate `alt` attribute.

A useful exercise would be to extend this example to make use of the provided HelloWidget component.
2 changes: 1 addition & 1 deletion accessibility-checker/boilerplates/jest/src/HelloWidget.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ var HelloWidget = React.createClass({
}
});

module.exports = HelloWidget;
module.exports = HelloWidget;
20 changes: 10 additions & 10 deletions accessibility-checker/boilerplates/jest/test/basic.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
*/
'use strict';

var path = require("path");

// Describe this Suite of testscases, describe is a test Suite and 'it' is a testcase.
describe("Hello World Basics", () => {
describe("Hello World - Baseline Basics", () => {
test("Image missing alt w/ Baseline", async () => {
document.body.innerHTML = "<div><img src='hello.png' /></div>";
await expect(document).toBeAccessible("IMG_BASELINE");
document.body.innerHTML = "<div><img src='hello.png' /></div>"
// We expect this test to pass because it will find baselines/IMG_BASELINE.json
// The checker will ignore issues stored in the baseline
await expect(document).toBeAccessible("IMG_BASELINE")
});
test("Image missing alt without Baseline", async () => {
document.body.innerHTML = "<div><img src='hello.png' /></div>";
await expect(document).toBeAccessible("IMG_NO_BASELINE");
});
});
// If you add alt='anything' you will no longer see the 'The image has neither an accessible name nor is marked as decorative or redundant' message
document.body.innerHTML = "<div><img src='hello.png' /></div>"
await expect(document).toBeAccessible("IMG_NO_BASELINE")
})
})
Loading