observable.spec.js 669 B

123456789101112131415161718192021222324252627282930
  1. import Vue from 'vue'
  2. describe('Global API: observable', () => {
  3. it('should work', done => {
  4. const state = Vue.observable({
  5. count: 0
  6. })
  7. const app = new Vue({
  8. render(h) {
  9. return h('div', [
  10. h('span', state.count),
  11. h('button', {
  12. on: {
  13. click: () => {
  14. state.count++
  15. }
  16. }
  17. }, '+')
  18. ])
  19. }
  20. }).$mount()
  21. expect(app.$el.querySelector('span').textContent).toBe('0')
  22. app.$el.querySelector('button').click()
  23. waitForUpdate(() => {
  24. expect(app.$el.querySelector('span').textContent).toBe('1')
  25. }).then(done)
  26. })
  27. })