$dispatch.spec.js 497 B

12345678910111213141516
  1. import { haveText, html, test } from '../../utils'
  2. test('$dispatch dispatches events properly',
  3. html`
  4. <div x-data="{ foo: 'bar' }" x-on:custom-event="foo = $event.detail.newValue">
  5. <span x-text="foo"></span>
  6. <button x-on:click="$dispatch('custom-event', {newValue: 'baz'})">click me</button>
  7. </div>
  8. `,
  9. ({ get }) => {
  10. get('span').should(haveText('bar'))
  11. get('button').click()
  12. get('span').should(haveText('baz'))
  13. }
  14. )