Journal
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!");
})
})
A new technique for making responsive, JavaScript-free charts (DEV Community)
I wanted to see if it was possible to create SVG charts that would work without JS. Well, it is. I've also created an experimental Svelte component library called Pancake to make these techniques easier to use.
A lovely modern, progressively-enhanced approach to data visualisation that uses primarily SVG, HTML and CSS but can be enhanced with JavaScript for Node-based generation or client-side interactivity, if required. (via @jamesmockett)
Let’s Learn Eleventy! (with Zach Leatherman) - Learn With Jason (YouTube)
A great tutorial video on Eleventy by Jason Lengstorf with guest Zach Leatherman, creator of Eleventy.
I already know Eleventy pretty well – in fact this site is built with Eleventy. But you always pick up lots of great tips by watching the people who really know their way around the software.
(via @jlengstorf)
RegExr: Learn, Build, and Test RegEx
RegExr is an online tool to learn, build, & test Regular Expressions.
This handy, interactive tool is a bit like Postman but for RegEx. You can create RegEx patterns and save them for easy retrieval later.
I also like the way you can start by making a list of example text strings you want your pattern to i) match and ii) not match before starting work on your RegEx pattern, adopting a sort-of “Test Driven RegEx” approach.
Clair and I just watched The Farewell, a comedy-drama film written and directed by Lulu Wang starring Awkwafina and Zhao Shuzhen, and really enjoyed it. Interesting/difficult subject matter and really nicely done. If you need a break from grisly murder cases etc then I can heartily recommend it.
BBC Four - Primal Scream: The Lost Memphis Tapes
The sessions recorded by the band in Memphis with the legendary record producer Tom Dowd, along with the Muscle Shoals Rhythm Section musicians Roger Hawkins, drums, and David Hood, bass, did not make the light of day, because some of the mixes were not suitable in the musical climate at the time.
A great watch telling an unlikely, touching and at times hilarious story of how the Glasgow band temporarily escaped the madness of the early 90’s scene for Memphis to record an album which was out of step with the time and only revealed its true quality with the benefit of hindsight and maturity.
The production on The Memphis Sessions sounded absolutely amazing and there are some great vinyl mastering scenes for those – like myself – who are into that kind of thing!
On the strength of this, I think Clair and I will grab a copy of the record.
As I got on my usual bus from Stockwell St to Vic Rd this eve, I noticed it was the same driver whose bus I’d taken twice last week and both times it had broken down – that’s two days in a row – leaving me to walk home in the usual January post-apocalyptic shitstorm. I got on his bus today and no sooner was it 200 yards down the road than it crashed into a taxi, across from Marks and Sparks. Everybody out – again. That’s 3 times I’ve been on his bus, and three times it’s broken down for one reason or another. The shittest hat-trick ever 😂. I need to find out this guy’s name so I can never get on a plane with him.
Not every Design System Pattern should be represented by a component (CSS-Tricks)
My point with all this is that it’s easy to see every problem or design as a new component or a mix of currently existing components. But instead, we should make components that can slot into each other neatly, rather just continue to make more components.
An interesting observation from Robin Rendle who leads Gousto’s design system.
Not every design pattern in a Design System should be represented by a code-based component.
His example is of the common link-with-icon pattern (but the theory could be applied elsewhere).
Gousto already had <Link />
and <Icon />
components, each with their own relevant props (e.g name
etc) but because the designs often featured links-with-icons they decided to build an <IconLink />
component too.
This new component introduced new, repetitious but slightly divergent prop/attribute names.
Robin’s point is that the new component essentially:
- just duplicated what the existing components did, and thus
- created margin for divergence and error, and
- added additional maintenance overhead.
So Gousto eventually realised that an additional coded component didn’t make sense. Instead, just combine the existing components by nesting an <Icon />
inside a <Link />
, e.g.:
<Link>
<Icon />
<Link>
I like his thinking!
Basically there doesn’t need to be (and shouldn’t be, to avoid coding error and UX inconsistency) a 1:1 relationship between design patterns and coded components, so long as the pattern can be created by composition using existing components.
Note that I think it’s still key to document how to recreate the design pattern in code – for example we could have a section at the bottom of the component docs for the Icon
component detailing how to create a link-with-icon by combining it with a Link
component.
Basically I like the idea of reducing the amount of
- “which component do I use?” head-scratching; and
- margin for divergence/inconsistency
…by having less components.
A Modern Typographic Scale (on 24 ways)
Here’s Rob Weychert advocating a combination of CSS custom properties, calc()
and Sass to automate the construction of a flexible typographic scale in CSS.
Awesome Stock Resources
A collection of links for free stock photography, video and illustration websites
In case I need more stock photography than I currently get from Unsplash, this Github-hosted list could be useful.
Aside from photography it also lists resources for free illustrations, video, CSS background tiles and more.