1
0

external.spec.js 910 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. let { morph } = require('@alpinejs/morph')
  2. let createElement = require('./createElement.js')
  3. test('text content', () => assertPatch(
  4. `<div>foo</div>`,
  5. `<div>bar</div>`
  6. ))
  7. test('change tag', () => assertPatch(
  8. `<div><div>foo</div></div>`,
  9. `<div><span>foo</span></div>`
  10. ))
  11. test('add child', () => assertPatch(
  12. `<div>foo</div>`,
  13. `<div>foo <h1>baz</h1></div>`
  14. ))
  15. test('remove child', () => assertPatch(
  16. `<div>foo <h1>baz</h1></div>`,
  17. `<div>foo</div>`
  18. ))
  19. test('add attribute', () => assertPatch(
  20. `<div>foo</div>`,
  21. `<div foo="bar">foo</div>`
  22. ))
  23. test('remove attribute', () => assertPatch(
  24. `<div foo="bar">foo</div>`,
  25. `<div>foo</div>`
  26. ))
  27. test('change attribute', () => assertPatch(
  28. `<div foo="bar">foo</div>`,
  29. `<div foo="baz">foo</div>`
  30. ))
  31. function assertPatch(before, after) {
  32. expect(morph(createElement(before), after).outerHTML).toEqual(after)
  33. }