Hi, this might not be the right place to ask but I've got a fully running AngularJS app with raven-js integrated nicely reporting back to GetSentry.
However when I run karma against the app.js file it fails with:
TypeError: undefined is not a function
at Object.Raven.config (http://localhost:9876/base/build/bower/raven-js/dist/raven.js:1155:36)
at http://localhost:9876/base/build/bower/angular-raven/angular-raven.js:32:19
at Object.invoke (http://localhost:9876/base/build/bower/angular/angular.js:3906:17)
at origProvider.$get (http://localhost:9876/base/build/bower/angular/angular.js:3802:31)
at Object.invoke (http://localhost:9876/base/build/bower/angular/angular.js:3906:17)
at http://localhost:9876/base/build/bower/angular/angular.js:3747:37
at getService (http://localhost:9876/base/build/bower/angular/angular.js:3869:39)
at Object.invoke (http://localhost:9876/base/build/bower/angular/angular.js:3896:13)
at http://localhost:9876/base/build/bower/angular/angular.js:3747:37
at getService (http://localhost:9876/base/build/bower/angular/angular.js:3869:39)
I'm using raven-js to intercept all $http requests if they aren't 200.
Removing all of my raven-js code means the test go back to passing so I'm guessing I haven't got something set up right.
An example test:
describe('Unit Test Suite', function() {
beforeEach(module('myApp'));
it('should inject client services', inject(
function(
ClientsFactory,
ClientFactory
) {
expect(ClientsFactory).toBeDefined();
expect(ClientFactory).toBeDefined();
}
));
});
Any help gratefully received :)
I just had same error and fixed by adding raven-js to the list of files downloaded in your karma config file:
files: [
....
'http://cdn.ravenjs.com/1.1.16/angular,jquery,native/raven.min.js'
],
and now Im getting a full test pass but one error line per test:
ERROR: 'Error: Raven has already been configured'
:)
@kylezeeuwen did you manage to get rid of 'Error: Raven has already been configured'?
I am trying to exclude raven from my karma tests but not having any luck.
Just for context, that's only written out to window.console
. It's not raising an exception or anything.
@mattrobenolt cool, thanks. I'd still want to prevent loading raven in tests. I would come in handy when excluding other sources as well that act up during tests. Any suggestions?
At the moment i'm trying to exclude raven using config:
exclude: [].concat(
clientApp + 'util/raven.js'
)
Oh, I've never used karma, so I have no idea. :)
Hi @silentFred , it was 5 months ago so I don't really recall what my solution was, but I have found this snippet in our karma "setup utils" library that apparently I added in Oct 2014 that looks relevant:
loadApp: () ->
addRavenErrorStub = () ->
window.Raven =
config: ->
install: ->
beforeEach addRavenErrorStub
beforeEach window.angular.mock.module '<YOURAPP>'
This is written in coffeescript, but basically says before loading your app replace the window.raven object with a stub that has a config function, and that config function returns an object that has an install function, which does nothing. That should stub out raven for you in your karma tests.
HTH
To elaborate on kylezeeuwen's answer for anyone who sees this down the line, you can put this function:
function sharedTestSetup() {
beforeEach(function() {
window.Raven = {
config: function() {
return {
install: function () {}
};
}
};
});
};
in a separate file and load it in your karma.conf.js before your spec files. Then you can call sharedTestSetup() in any tests (within the describe function before any other code) that the Raven error is an issue. I'm not sure if it's the most elegant solution (I'm fairly new to karma+jasmine), but it's about as dry as I could make it.
Most helpful comment
To elaborate on kylezeeuwen's answer for anyone who sees this down the line, you can put this function:
in a separate file and load it in your karma.conf.js before your spec files. Then you can call sharedTestSetup() in any tests (within the describe function before any other code) that the Raven error is an issue. I'm not sure if it's the most elegant solution (I'm fairly new to karma+jasmine), but it's about as dry as I could make it.