|
| 1 | +var _Raven = require('../../src/raven'); |
| 2 | +var vuePlugin = require('../../plugins/vue'); |
| 3 | + |
| 4 | +var Raven; |
| 5 | +describe('Vue plugin', function () { |
| 6 | + beforeEach(function () { |
| 7 | + Raven = new _Raven(); |
| 8 | + Raven.config('http://[email protected]:80/2'); |
| 9 | + }); |
| 10 | + |
| 11 | + describe('errorHandler', function () { |
| 12 | + beforeEach(function () { |
| 13 | + this.sinon.stub(Raven, 'captureException'); |
| 14 | + this.MockVue = { |
| 15 | + config: {}, |
| 16 | + util: { |
| 17 | + formatComponentName: function() { |
| 18 | + return '<root component>' |
| 19 | + } |
| 20 | + } |
| 21 | + }; |
| 22 | + }); |
| 23 | + |
| 24 | + it('should capture component name and propsData', function () { |
| 25 | + vuePlugin(Raven, this.MockVue); |
| 26 | + |
| 27 | + this.MockVue.config.errorHandler(new Error('foo'), { |
| 28 | + $options: { |
| 29 | + propsData: { |
| 30 | + foo: 'bar' |
| 31 | + } |
| 32 | + } |
| 33 | + }, {} /* vm */); |
| 34 | + |
| 35 | + assert.isTrue(Raven.captureException.calledOnce); |
| 36 | + |
| 37 | + assert.deepEqual(Raven.captureException.args[0][1].extra, { |
| 38 | + propsData: { |
| 39 | + foo: 'bar' |
| 40 | + }, |
| 41 | + componentName: '<root component>' |
| 42 | + }); |
| 43 | + }); |
| 44 | + |
| 45 | + it('should call the existing error handler', function () { |
| 46 | + var errorHandler = this.sinon.stub(); |
| 47 | + this.MockVue.config.errorHandler = errorHandler; |
| 48 | + vuePlugin(Raven, this.MockVue); // should override errorHandler |
| 49 | + |
| 50 | + var err = new Error('foo'); |
| 51 | + var vm = { |
| 52 | + $options: { propsData: {} } |
| 53 | + }; |
| 54 | + this.MockVue.config.errorHandler(err, vm); |
| 55 | + |
| 56 | + assert.isTrue(Raven.captureException.calledOnce); |
| 57 | + assert.isTrue(errorHandler.calledOnce); |
| 58 | + assert.equal(errorHandler.args[0][0], err); |
| 59 | + assert.equal(errorHandler.args[0][1], vm); |
| 60 | + }); |
| 61 | + }); |
| 62 | +}); |
0 commit comments