Skip to content

Instantly share code, notes, and snippets.

View djfpaagman's full-sized avatar

Dennis Paagman djfpaagman

View GitHub Profile
@bholtbholt
bholtbholt / _stimulus-helper.js
Last active May 2, 2024 13:50
Testing Stimulus with Jest in a Rails App. Stimulus isn't mounted before the test runs, so these helpers wrap the calls in async functions to fix race conditions.
// This helper file provides a consistent API for testing Stimulus Controllers
//
// Use:
// import { getHTML, setHTML, startStimulus } from './_stimulus_helper';
// import MyController from '@javascripts/controllers/my_controller';
//
// beforeEach(() => startStimulus('my', MyController));
// test('should do something', async () => {
// await setHTML(`<button data-controller="my" data-action="my#action">click</button>`);
//