Tagged “testing”
This week I used an accordion (by Adam Silver)
I loved this insight into Adam Silver’s thought process. And it came at a timely moment since at work I’m currently trying to promote evidence-based, considered choices regarding user interface patterns.
My summary of Adam’s key points is:
- he found a UI pattern (let’s call it pattern x) in his project and flagged that while it’s not always bad it risks numerous usability problems. He lists these problems.
- he advises that pattern x is beneficial only in very specific situation y
- and that otherwise, pattern x is unnecessary and a more basic solution would not only require less work but provide a better user experience
- given this context, he asks others working on the project the following:
- can they explain why pattern x was used?
- did research (really) indicate a need? (this implicitly also asks if evidence or research was considered at all)
- what else was tried beforehand? (this also subtly checks for awareness of the risks of pattern x and whether other options were even considered)
- even if the use case was appropriate, given the downsides of pattern x were you comfortable the benefits outweigh those?
Adam also mentions how on this occasion, in the end, he had to grudgingly stick with pattern x because even though there were possible alternatives, his team didn’t have time to research or implement them. A familiar dose of real life, there. It’s worth being clear, though, that their implementation of pattern x (an accordion) is at least accessible, since as far as I can tell it uses their modern accordion design system component. If that were not the case, I imagine it’d be even less viable to leave it in place.
Testing ES modules with Jest
Here are a few troubleshooting tips to enable Jest, the JavaScript testing framework, to be able to work with ES modules without needing Babel in the mix for transpilation. Let’s get going with a basic set-up.
package.json
…,
"scripts": {
"test": "NODE_ENV=test NODE_OPTIONS=--experimental-vm-modules jest"
},
"type": "module",
"devDependencies": {
"jest": "^27.2.2"
}
Note: take note of the crucial "type": "module"
part as it’s the least-documented bit and your most likely omission!
After that set-up, you’re free to import
and export
to your heart’s content.
javascript/sum.js
export const sum = (a, b) => {
return a + b;
}
spec/sum.test.js
import { sum } from "../javascript/sum.js";
test('adds 1 + 2 to equal 3', () => {
expect(sum(1, 2)).toBe(3);
});
Hopefully that’ll save you (and future me) some head-scratching.
(Reference: Jest’s EcmaScript Modules docs page)
Accessibility Testing (on adactio.com)
In this journal entry, Jeremy Keith argues that when it comes to accessibility testing it’s not just about finding issues—it’s about finding the issues at the right time.
Here’s my summary:
- Accessibility Audits performed by experts and real Assistive Technology users are good!
- But try to get the most out of them by having them focus on the things that you can’t easily do yourself.
- We ourselves can handle things like colour contrast. It can be checked at the design stage before a line of code is written.
- Likewise HTML structure such as ensuring accessible form labels, ensuring images have useful
alt
values, using landmarks likemain
andnav
, heading structure etc. These are not tricky to find and fix ourselves and they have a big accessibility impact. - As well as fixing those issues ourselves we should also put in place new processes, checks and automation if possible to stop them recurring
- As for custom interactive elements (tabs, carousels, navigation, dropdowns): these are specific to our site and complicated/error-prone by nature, so those are the things we should be aiming to have professional Accessibility Audits focus on in order to get best value for money.
Use Mac Zoom to show the text a screen reader gets
I picked up a good accessibility testing tip from my work colleague Max today.
On a Mac, if you open System > Accessibility > Zoom, you can enable “hover text”. This allows you to hold down command (cmd) and then whatever is under the mouse will be shown. This shows the same text that a screen reader sees so it’s good for checking if bits of the page respond to a screen reader.
Assistiv Labs
A tool for testing how accessible your experience is on various assistive technologies – perhaps “like BrowserStack but for screen readers”?
Assistiv Labs remotely connects you to real assistive technologies, like NVDA, VoiceOver, and TalkBack, using any modern web browser.
I use a Mac for development which means that when I do screen reader testing I use the Mac’s VoiceOver tool. However the majority of screen reader users are using NVDA via Firefox on a PC. Perhaps this tool might let me test on that stack without buying a PC.
Next action: sign up for a free trial and give it a go!
(via Matthew and @paddyduke)
Introducing Rome
We’re excited to announce the first beta release and general availability of the Rome linter for JavaScript and TypeScript. This is the beginning of an entire suite of tools. Rome is not only a linter, but also a compiler, bundler, test runner, and more, for JavaScript, TypeScript, HTML, JSON, Markdown, and CSS. We aim to unify the entire frontend development toolchain.
A very ambitious project from the creator of Babel.
Testing Stimulus Controllers
Stimulus JS is great but doesn’t provide any documentation for testing controllers, so here’s some of my own that I’ve picked up.
Required 3rd-party libraries
Basic Test
// hello_controller.test.js
import { Application as StimulusApp } from "stimulus";
import HelloController from "path/to/js/hello_controller";
describe("HelloController", () => {
beforeEach(() => {
// Insert the HTML and register the controller
document.body.innerHTML = `
<div data-controller="hello">
<input data-target="hello.name" type="text">
<button data-action="click->hello#greet">
Greet
</button>
<span data-target="hello.output">
</span>
</div>
`;
StimulusApp.start().register('hello', HelloController);
})
it("inserts a greeting using the name given", () => {
const helloOutput = document.querySelector("[data-target='hello.output']");
const nameInput = document.querySelector("[data-target='hello.name']");
const greetButton = document.querySelector("button");
// Change the input value and click the greet button
nameInput.value = "Laurence";
greetButton.click();
// Check we have the correct greeting
expect(helloOutput).toHaveTextContent("Hello, Laurence!");
})
})
Beyond Automatic Testing (matuzo.at)
Six accessibility tests Viennese Front-end Developer Manuel Matusovic runs on every website he develops, beyond simply running a Lighthouse audit.
Includes “Test in Grayscale Mode” and “Test with no mouse to check tabbing and focus styles”.
See all tags.