expression.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /* global normal, attrs, html */
  2. casper.test.begin('Expression', 23, function (test) {
  3. casper
  4. .start('./fixtures/expression.html')
  5. .then(function () {
  6. test.assertSelectorHasText('#normal p', 'Hello World!')
  7. test.assertSelectorHasText('#lazy p', 'Hi Ho!')
  8. test.assertField('one', 'Hello')
  9. test.assertField('two', 'World')
  10. test.assertField('three', 'Hi')
  11. test.assertField('four', 'Ho')
  12. // attrs
  13. test.assertEval(function () {
  14. return document.getElementById('attrs').dataset.test === 'hi hoef ha'
  15. })
  16. })
  17. .thenEvaluate(function () {
  18. // setting value
  19. normal.one = 'Hola'
  20. })
  21. .then(function () {
  22. test.assertSelectorHasText('#normal p', 'Hola World!')
  23. test.assertField('one', 'Hola')
  24. })
  25. .thenEvaluate(function () {
  26. // setting nested value
  27. normal.two.three = 'Casper'
  28. })
  29. .then(function () {
  30. test.assertSelectorHasText('#normal p', 'Hola Casper!')
  31. test.assertField('two', 'Casper')
  32. })
  33. .then(function () {
  34. // lazy input
  35. this.fill('#form', {
  36. three: 'three',
  37. four: 'four'
  38. })
  39. })
  40. .then(function () {
  41. test.assertSelectorHasText('#lazy p', 'three four!')
  42. })
  43. .then(function () {
  44. // normal input
  45. this.sendKeys('#one', 'Bye')
  46. })
  47. .then(function () {
  48. test.assertSelectorHasText('#normal p', 'Bye Casper!')
  49. })
  50. // v-on with expression
  51. .thenClick('#normal button', function () {
  52. test.assertField('one', 'clicked')
  53. test.assertSelectorHasText('#normal p', 'clicked Casper!')
  54. })
  55. // v-on with expression
  56. .thenClick('#lazy button', function () {
  57. test.assertField('four', 'clicked')
  58. test.assertSelectorHasText('#lazy p', 'three clicked!')
  59. })
  60. // conditional expression
  61. // e.g. ok ? yesMSg : noMsg
  62. // make sure all three are captured as dependency
  63. .then(function () {
  64. test.assertSelectorHasText('#conditional p', 'YES')
  65. })
  66. .thenClick('#conditional .toggle', function () {
  67. test.assertSelectorHasText('#conditional p', 'NO')
  68. })
  69. .thenClick('#conditional .change', function () {
  70. test.assertSelectorHasText('#conditional p', 'Nah')
  71. })
  72. .thenEvaluate(function () {
  73. attrs.msg = 'hoho'
  74. })
  75. .then(function () {
  76. // attr
  77. test.assertEvalEquals(function () {
  78. return document.getElementById('attrs').dataset.test
  79. }, 'hi hohoef ha')
  80. // html
  81. test.assertEvalEquals(function () {
  82. return document.getElementById('html').innerHTML
  83. }, 'html <p>should</p> <a>probably</a><!--v-html--> work')
  84. })
  85. .thenEvaluate(function () {
  86. html.html = '<span>should</span> <a>change work</a>'
  87. })
  88. .then(function () {
  89. test.assertEvalEquals(function () {
  90. return document.getElementById('html').innerHTML
  91. }, 'html <span>should</span> <a>change work</a><!--v-html--> work')
  92. })
  93. .run(function () {
  94. test.done()
  95. })
  96. })