diff options
author | Luke "Jared" Bennett <lbennett@gitlab.com> | 2017-04-15 05:38:59 +0300 |
---|---|---|
committer | Luke "Jared" Bennett <lbennett@gitlab.com> | 2017-04-15 05:38:59 +0300 |
commit | e22bd9650d7bebfea0909fdaf5be7dcf746b53f7 (patch) | |
tree | bdcc94b5136ad14eabf2066f56ac654e04fa9a01 /spec/javascripts/raven/raven_config_spec.js | |
parent | 067361327bba0cb7a8b28190485699da7deb22bb (diff) |
Updated specs, added rewire, updated layouts to move conditional raven and gon to head
Diffstat (limited to 'spec/javascripts/raven/raven_config_spec.js')
-rw-r--r-- | spec/javascripts/raven/raven_config_spec.js | 70 |
1 files changed, 63 insertions, 7 deletions
diff --git a/spec/javascripts/raven/raven_config_spec.js b/spec/javascripts/raven/raven_config_spec.js index 3885cfde6bf..b8bb558d22e 100644 --- a/spec/javascripts/raven/raven_config_spec.js +++ b/spec/javascripts/raven/raven_config_spec.js @@ -1,8 +1,7 @@ -import $ from 'jquery'; import Raven from 'raven-js'; -import RavenConfig from '~/raven/raven_config'; +import RavenConfig, { __RewireAPI__ as RavenConfigRewire } from '~/raven/raven_config'; -fdescribe('RavenConfig', () => { +describe('RavenConfig', () => { describe('init', () => { let options; @@ -116,21 +115,78 @@ fdescribe('RavenConfig', () => { }); describe('bindRavenErrors', () => { + let $document; + let $; + beforeEach(() => { + $document = jasmine.createSpyObj('$document', ['on']); + $ = jasmine.createSpy('$').and.returnValue($document); + + RavenConfigRewire.__set__('$', $); + RavenConfig.bindRavenErrors(); }); it('should query for document using jquery', () => { - console.log($, 'or', $.fn); - // expect($).toHaveBeenCalledWith() + expect($).toHaveBeenCalledWith(document); }); it('should call .on', function () { - // expect($document.on).toHaveBeenCalledWith('ajaxError.raven', RavenConfig.handleRavenErrors); + expect($document.on).toHaveBeenCalledWith('ajaxError.raven', RavenConfig.handleRavenErrors); }); }); describe('handleRavenErrors', () => { - beforeEach(() => {}); + let event; + let req; + let config; + let err; + + beforeEach(() => { + event = {}; + req = { status: 'status', responseText: 'responseText', statusText: 'statusText' }; + config = { type: 'type', url: 'url', data: 'data' }; + err = {}; + + spyOn(Raven, 'captureMessage'); + + RavenConfig.handleRavenErrors(event, req, config, err); + }); + + it('should call Raven.captureMessage', () => { + expect(Raven.captureMessage).toHaveBeenCalledWith(err, { + extra: { + type: config.type, + url: config.url, + data: config.data, + status: req.status, + response: req.responseText.substring(0, 100), + error: err, + event, + }, + }); + }); + + describe('if no err is provided', () => { + beforeEach(() => { + Raven.captureMessage.calls.reset(); + + RavenConfig.handleRavenErrors(event, req, config); + }); + + it('should use req.statusText as the error value', () => { + expect(Raven.captureMessage).toHaveBeenCalledWith(req.statusText, { + extra: { + type: config.type, + url: config.url, + data: config.data, + status: req.status, + response: req.responseText.substring(0, 100), + error: req.statusText, + event, + }, + }); + }); + }); }); }); |