config.spec.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. it('should capture user watcher callback errors', done => {
  33. const spy = jasmine.createSpy('errorHandler')
  34. Vue.config.errorHandler = spy
  35. const err = new Error()
  36. const vm = new Vue({
  37. data: { a: 1 },
  38. watch: {
  39. a: () => {
  40. throw err
  41. }
  42. }
  43. }).$mount()
  44. vm.a = 2
  45. waitForUpdate(() => {
  46. expect(spy).toHaveBeenCalledWith(err, vm)
  47. Vue.config.errorHandler = null
  48. }).then(done)
  49. })
  50. })
  51. describe('optionMergeStrategies', () => {
  52. it('should allow defining custom option merging strategies', () => {
  53. const spy = jasmine.createSpy('option merging')
  54. Vue.config.optionMergeStrategies.__test__ = (parent, child, vm) => {
  55. spy(parent, child, vm)
  56. return child + 1
  57. }
  58. const Test = Vue.extend({
  59. __test__: 1
  60. })
  61. expect(spy.calls.count()).toBe(1)
  62. expect(spy).toHaveBeenCalledWith(undefined, 1, undefined)
  63. expect(Test.options.__test__).toBe(2)
  64. const test = new Test({
  65. __test__: 2
  66. })
  67. expect(spy.calls.count()).toBe(2)
  68. expect(spy).toHaveBeenCalledWith(2, 2, test)
  69. expect(test.$options.__test__).toBe(3)
  70. })
  71. })
  72. })