config.spec.js 2.2 KB

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