UNPKG

@kanety/stimulus-static-actions

Version:

A stimulus extension to define actions in controller

27 lines (21 loc) 614 B
import { Application, Controller } from '@hotwired/stimulus'; class TestController extends Controller { static actions = [['element', 'click@window->show']]; show(e) { $('button').innerHTML = 'Clicked'; } } const application = Application.start(); application.register('test', TestController); describe('target window', () => { beforeEach(() => { document.body.innerHTML = ` <div data-controller="test"> <button type="button">Test</button> </div>`; }); it('calls action', () => { $('button').click(); expect($('button').innerHTML).toEqual('Clicked'); }); });