init_spec.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. var Vue = require('src')
  2. var init = Vue.prototype._init
  3. describe('Instance Init', function () {
  4. var stub = {
  5. constructor: {
  6. options: { a: 1, b: 2 }
  7. },
  8. _updateRef: jasmine.createSpy(),
  9. _initEvents: jasmine.createSpy(),
  10. _callHook: jasmine.createSpy(),
  11. _initState: jasmine.createSpy(),
  12. $mount: jasmine.createSpy()
  13. }
  14. var options = {
  15. a: 2,
  16. el: {}
  17. }
  18. init.call(stub, options)
  19. it('should setup properties', function () {
  20. expect(stub.$el).toBe(null)
  21. expect(stub.$root).toBe(stub)
  22. expect(stub.$refs).toBeTruthy()
  23. expect(stub.$els).toBeTruthy()
  24. expect(stub._watchers).toBeTruthy()
  25. expect(stub._directives).toBeTruthy()
  26. expect(stub._events).toBeTruthy()
  27. expect(stub._eventsCount).toBeTruthy()
  28. })
  29. it('should merge options', function () {
  30. expect(stub.$options.a).toBe(2)
  31. expect(stub.$options.b).toBe(2)
  32. })
  33. it('should call other init methods', function () {
  34. expect(stub._initEvents).toHaveBeenCalled()
  35. expect(stub._initState).toHaveBeenCalled()
  36. expect(stub._updateRef).toHaveBeenCalled()
  37. })
  38. it('should call created hook', function () {
  39. expect(stub._callHook).toHaveBeenCalledWith('created')
  40. })
  41. it('should call $mount when options.el is present', function () {
  42. expect(stub.$mount).toHaveBeenCalledWith(stub.$options.el)
  43. })
  44. })