UNPKG

alpinejs

Version:

Alpine.js offers you the reactive and declarative nature of big frameworks like Vue or React at a much lower cost.

25 lines (17 loc) 620 B
import Alpine from 'alpinejs' import { wait } from '@testing-library/dom' global.MutationObserver = class { observe() {} } test('can reference elements from event listeners', async () => { document.body.innerHTML = ` <div x-data="{}"> <span x-ref="bob"></span> <button x-on:click="$refs['bob'].innerText = 'lob'"></button> </div> ` Alpine.start() expect(document.querySelector('span').innerText).toEqual(undefined) document.querySelector('button').click() await wait(() => { expect(document.querySelector('span').innerText).toEqual('lob') }) })