expression.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /* global normal */
  2. casper.test.begin('Expression', 19, 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. })
  13. .thenEvaluate(function () {
  14. // setting value
  15. normal.one = 'Hola'
  16. })
  17. .then(function () {
  18. test.assertSelectorHasText('#normal p', 'Hola World!')
  19. test.assertField('one', 'Hola')
  20. })
  21. .thenEvaluate(function () {
  22. // setting nested value
  23. normal.two.three = 'Casper'
  24. })
  25. .then(function () {
  26. test.assertSelectorHasText('#normal p', 'Hola Casper!')
  27. test.assertField('two', 'Casper')
  28. })
  29. .then(function () {
  30. // lazy input
  31. this.fill('#form', {
  32. three: 'three',
  33. four: 'four'
  34. })
  35. })
  36. .then(function () {
  37. test.assertSelectorHasText('#lazy p', 'three four!')
  38. })
  39. .then(function () {
  40. // normal input
  41. this.sendKeys('#one', 'Bye')
  42. })
  43. .then(function () {
  44. test.assertSelectorHasText('#normal p', 'Bye Casper!')
  45. })
  46. // v-on with expression
  47. .thenClick('#normal button', function () {
  48. test.assertField('one', 'clicked')
  49. test.assertSelectorHasText('#normal p', 'clicked Casper!')
  50. })
  51. // v-on with expression
  52. .thenClick('#lazy button', function () {
  53. test.assertField('four', 'clicked')
  54. test.assertSelectorHasText('#lazy p', 'three clicked!')
  55. })
  56. // conditional expression
  57. // e.g. ok ? yesMSg : noMsg
  58. // make sure all three are captured as dependency
  59. .then(function () {
  60. test.assertSelectorHasText('#conditional p', 'YES')
  61. })
  62. .thenClick('#conditional .toggle', function () {
  63. test.assertSelectorHasText('#conditional p', 'NO')
  64. })
  65. .thenClick('#conditional .change', function () {
  66. test.assertSelectorHasText('#conditional p', 'Nah')
  67. })
  68. .run(function () {
  69. test.done()
  70. })
  71. })