1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- import { haveText, html, test } from '../utils'
- test('element side effects are cleaned up after the elements are removed',
- html`
- <div x-data="{ foo: 1, bar: 1 }">
- <button @click="bar++">bar</button>
- <a href="#" @click.prevent="$refs.span.remove()">remove</a>
- <span x-text="(() => { foo = foo + 1; return bar })" x-ref="span"></span>
- <h1 x-text="foo"></h1>
- <h2 x-text="bar"></h2>
- </div>
- `,
- ({ get }) => {
- get('h1').should(haveText('2'))
- get('h2').should(haveText('1'))
- get('button').click()
- get('h1').should(haveText('3'))
- get('h2').should(haveText('2'))
- get('a').click()
- get('button').click()
- get('h1').should(haveText('3'))
- get('h2').should(haveText('3'))
- }
- )
- test('nested element side effects are cleaned up after the parent is removed',
- html`
- <div x-data="{ foo: 1, bar: 1 }">
- <button @click="bar++">bar</button>
- <a href="#" @click.prevent="$refs.article.remove()">remove</a>
- <article x-ref="article">
- <span x-text="(() => { foo = foo + 1; return bar })"></span>
- </article>
- <h1 x-text="foo"></h1>
- <h2 x-text="bar"></h2>
- </div>
- `,
- ({ get }) => {
- get('h1').should(haveText('2'))
- get('h2').should(haveText('1'))
- get('button').click()
- get('h1').should(haveText('3'))
- get('h2').should(haveText('2'))
- get('a').click()
- get('button').click()
- get('h1').should(haveText('3'))
- get('h2').should(haveText('3'))
- }
- )
- test('can mutate directive value',
- html`
- <div x-data="{ foo: 'bar', bar: 'baz' }">
- <button @click="$refs.target.setAttribute('x-text', 'bar')">change text</button>
- <span x-text="foo" x-ref="target"></span>
- </div>
- `,
- ({ get }) => {
- get('span').should(haveText('bar'))
- get('button').click()
- get('span').should(haveText('baz'))
- }
- )
- test('can add new directive',
- html`
- <div x-data="{ foo: 'bar' }">
- <button @click="$refs.target.setAttribute('x-text', 'foo')">change text</button>
- <span x-ref="target"></span>
- </div>
- `,
- ({ get }) => {
- get('span').should(haveText(''))
- get('button').click()
- get('span').should(haveText('bar'))
- }
- )
|