init_spec.js 1.4 KB

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