2
0

config.spec.js 1.7 KB

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