init_spec.js 1.3 KB

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