subscribe.spec.js 753 B

1234567891011121314151617181920212223242526
  1. import Spruce from '../dist/spruce'
  2. import { waitFor } from '@testing-library/dom'
  3. test('x-subscribe > correctly updates x-init directive', async () => {
  4. document.body.innerHTML = `
  5. <div x-subscribe></div>
  6. `
  7. Spruce.start()
  8. await waitFor(() => {
  9. expect(document.querySelector('div').getAttribute('x-init')).toEqual('$store = Spruce.subscribe($el)')
  10. })
  11. })
  12. test('x-subscribe > correctly updates x-init when already defined', async () => {
  13. document.body.innerHTML = `
  14. <div x-subscribe x-init="testing = true"></div>
  15. `
  16. Spruce.start()
  17. await waitFor(() => {
  18. expect(document.querySelector('div').getAttribute('x-init')).toEqual('$store = Spruce.subscribe($el); testing = true')
  19. })
  20. })