config.spec.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import Vue from 'vue'
  2. describe('Global config', () => {
  3. describe('silent', () => {
  4. it('should be false by default', () => {
  5. Vue.util.warn('foo')
  6. expect('foo').toHaveBeenWarned()
  7. })
  8. it('should work when set to true', () => {
  9. Vue.config.silent = true
  10. Vue.util.warn('foo')
  11. expect('foo').not.toHaveBeenWarned()
  12. Vue.config.silent = false
  13. })
  14. })
  15. describe('errorHandler', () => {
  16. it('should be called with correct args', () => {
  17. const spy = jasmine.createSpy('errorHandler')
  18. Vue.config.errorHandler = spy
  19. const err = new Error()
  20. const vm = new Vue({
  21. render () { throw err }
  22. }).$mount()
  23. expect(spy).toHaveBeenCalledWith(err, vm)
  24. Vue.config.errorHandler = null
  25. })
  26. })
  27. describe('optionMergeStrategies', () => {
  28. it('should allow defining custom option merging strategies', () => {
  29. const spy = jasmine.createSpy('option merging')
  30. Vue.config.optionMergeStrategies.__test__ = (parent, child, vm) => {
  31. spy(parent, child, vm)
  32. return child + 1
  33. }
  34. const Test = Vue.extend({
  35. __test__: 1
  36. })
  37. expect(spy.calls.count()).toBe(1)
  38. expect(spy).toHaveBeenCalledWith(undefined, 1, undefined)
  39. expect(Test.options.__test__).toBe(2)
  40. const test = new Test({
  41. __test__: 2
  42. })
  43. expect(spy.calls.count()).toBe(2)
  44. expect(spy).toHaveBeenCalledWith(2, 2, test)
  45. expect(test.$options.__test__).toBe(3)
  46. })
  47. })
  48. })