init_spec.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. _initEvents: jasmine.createSpy(),
  8. _callHook: jasmine.createSpy(),
  9. _initScope: jasmine.createSpy(),
  10. $mount: jasmine.createSpy()
  11. }
  12. var options = {
  13. a: 2,
  14. _anonymous: true,
  15. _parent: {
  16. _isAnonymous: true,
  17. $parent: {}
  18. },
  19. el: {}
  20. }
  21. init.call(stub, options)
  22. it('should setup properties', function () {
  23. expect(stub.$el).toBe(null)
  24. expect(stub.$root).toBe(stub)
  25. expect(stub.$).toBeTruthy()
  26. expect(stub._watcherList).toBeTruthy()
  27. expect(stub._watchers).toBeTruthy()
  28. expect(stub._userWatchers).toBeTruthy()
  29. expect(stub._directives).toBeTruthy()
  30. expect(stub._events).toBeTruthy()
  31. expect(stub._eventsCount).toBeTruthy()
  32. expect(stub._isAnonymous).toBe(true)
  33. })
  34. it('should merge options', function () {
  35. expect(stub.$options.a).toBe(2)
  36. expect(stub.$options.b).toBe(2)
  37. })
  38. it('should locate owner', function () {
  39. expect(stub._owner).toBe(options._parent.$parent)
  40. })
  41. it('should call other init methods', function () {
  42. expect(stub._initEvents).toHaveBeenCalled()
  43. expect(stub._initScope).toHaveBeenCalled()
  44. })
  45. it('should call created hook', function () {
  46. expect(stub._callHook).toHaveBeenCalledWith('created')
  47. })
  48. it('should call $mount when options.el is present', function () {
  49. expect(stub.$mount).toHaveBeenCalledWith(stub.$options.el)
  50. })
  51. })