repeat-object.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. casper.test.begin('Repeat properties of an Object', 28, function (test) {
  2. casper
  3. .start('./fixtures/repeat-object.html')
  4. .then(function () {
  5. test.assertElementCount('.primitive', 2)
  6. test.assertElementCount('.obj', 2)
  7. test.assertSelectorHasText('.primitive:nth-child(1)', 'a 1')
  8. test.assertSelectorHasText('.primitive:nth-child(2)', 'b 2')
  9. test.assertSelectorHasText('.obj:nth-child(1)', 'a hi!')
  10. test.assertSelectorHasText('.obj:nth-child(2)', 'b ha!')
  11. test.assertSelectorHasText('#primitive', '{"a":1,"b":2}')
  12. test.assertSelectorHasText('#obj', '{"a":{"msg":"hi!"},"b":{"msg":"ha!"}}')
  13. })
  14. .thenClick('#push', function () {
  15. test.assertElementCount('.primitive', 3)
  16. test.assertSelectorHasText('.primitive:nth-child(3)', 'c 3')
  17. test.assertSelectorHasText('#primitive', '{"a":1,"b":2,"c":3}')
  18. })
  19. .thenClick('#pop', function () {
  20. test.assertElementCount('.primitive', 2)
  21. test.assertSelectorHasText('#primitive', '{"a":1,"b":2}')
  22. })
  23. .thenClick('#shift', function () {
  24. test.assertElementCount('.obj', 1)
  25. test.assertSelectorHasText('.obj:nth-child(1)', 'b ha!')
  26. test.assertSelectorHasText('#obj', '{"b":{"msg":"ha!"}}')
  27. })
  28. .thenClick('#unshift', function () {
  29. test.assertElementCount('.obj', 2)
  30. test.assertSelectorHasText('.obj:nth-child(1)', 'c ho!')
  31. test.assertSelectorHasText('.obj:nth-child(2)', 'b ha!')
  32. test.assertSelectorHasText('#obj', '{"b":{"msg":"ha!"},"c":{"msg":"ho!"}}')
  33. })
  34. .thenClick('#splice', function () {
  35. test.assertElementCount('.obj', 2)
  36. test.assertSelectorHasText('.obj:nth-child(1)', 'c ho!')
  37. test.assertSelectorHasText('.obj:nth-child(2)', 'd he!')
  38. test.assertSelectorHasText('#obj', '{"c":{"msg":"ho!"},"d":{"msg":"he!"}}')
  39. })
  40. // changing the object syncs to repeater
  41. .thenClick('#set', function () {
  42. test.assertSelectorHasText('.primitive:nth-child(1)', 'a 3')
  43. test.assertSelectorHasText('.obj:nth-child(1)', 'c hu!')
  44. test.assertSelectorHasText('#primitive', '{"a":3,"b":2}')
  45. test.assertSelectorHasText('#obj', '{"c":{"msg":"hu!"},"d":{"msg":"he!"}}')
  46. })
  47. .run(function () {
  48. test.done()
  49. })
  50. })