init_spec.js 1.2 KB

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