2
0

output-object.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. casper.test.begin('Outputting Objects', 17, function (test) {
  2. casper
  3. .start('./fixtures/output-object.html')
  4. .then(function () {
  5. test.assertSelectorHasText('#data', '{"test":{"prop":1},"arr":[{"a":1}]}')
  6. test.assertSelectorHasText('#obj', '{"prop":1}')
  7. test.assertSelectorHasText('#arr', '[{"a":1}]')
  8. })
  9. // setting a nested property
  10. .thenEvaluate(function () {
  11. test.test.prop = 2
  12. })
  13. .then(function () {
  14. test.assertSelectorHasText('#data', '{"test":{"prop":2},"arr":[{"a":1}]}')
  15. test.assertSelectorHasText('#obj', '{"prop":2}')
  16. })
  17. // setting a nested object
  18. .thenEvaluate(function () {
  19. test.test = { hi:3 }
  20. })
  21. .then(function () {
  22. test.assertSelectorHasText('#data', '{"test":{"hi":3},"arr":[{"a":1}]}')
  23. test.assertSelectorHasText('#obj', '{"hi":3}')
  24. })
  25. // mutating an array
  26. .thenEvaluate(function () {
  27. test.arr.push({a:2})
  28. })
  29. .then(function () {
  30. test.assertSelectorHasText('#data', '{"test":{"hi":3},"arr":[{"a":1},{"a":2}]}')
  31. test.assertSelectorHasText('#arr', '[{"a":1},{"a":2}]')
  32. })
  33. // no length change mutate an array
  34. .thenEvaluate(function () {
  35. test.arr.reverse()
  36. })
  37. .then(function () {
  38. test.assertSelectorHasText('#data', '{"test":{"hi":3},"arr":[{"a":2},{"a":1}]}')
  39. test.assertSelectorHasText('#arr', '[{"a":2},{"a":1}]')
  40. })
  41. // setting objects inside Array
  42. .thenEvaluate(function () {
  43. test.arr[0].a = 3
  44. })
  45. .then(function () {
  46. test.assertSelectorHasText('#data', '{"test":{"hi":3},"arr":[{"a":3},{"a":1}]}')
  47. test.assertSelectorHasText('#arr', '[{"a":3},{"a":1}]')
  48. })
  49. // swap the array
  50. .thenEvaluate(function () {
  51. test.arr = [1,2,3]
  52. })
  53. .then(function () {
  54. test.assertSelectorHasText('#data', '{"test":{"hi":3},"arr":[1,2,3]}')
  55. test.assertSelectorHasText('#arr', '[1,2,3]')
  56. })
  57. // setting $data
  58. .thenEvaluate(function () {
  59. test.$data = { test: { swapped: true }, arr:[3,2,1] }
  60. })
  61. .then(function () {
  62. test.assertSelectorHasText('#data', '{"test":{"swapped":true},"arr":[3,2,1]}')
  63. test.assertSelectorHasText('#obj', '{"swapped":true}')
  64. })
  65. .run(function () {
  66. test.done()
  67. })
  68. })