Running Karma/Jasmine tests against code with raven-js integrated
See original GitHub issueHi, 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 😃
Issue Analytics
- State:
- Created 9 years ago
- Comments:8 (2 by maintainers)
Top Results From Across the Web
Running tests with Karma and Jasmine manual
Karma is a console tool for running tests, which can track source code changes and display the percentage of code tests coverage.
Read more >Jasmine & Karma • Angular - codecraft.tv
Jasmine is a testing framework that supports Behavior-Driven Development. We write tests in Test Suites which are composed of one or more Test...
Read more >Angular Testing With Jasmine And Karma Using Selenium ...
A comprehensive tutorial on how to perform Angular testing with Jasmine and Karma using Selenium.
Read more >Angular Unit Testing Using Jasmine and Karma - eSketchers
This Angular unit testing tutorial with examples covers how to test a service & a component Using Jasmine and Karma.
Read more >Cross-platform testing of TypeScript code with Jasmine and ...
content. Enter Karma; Writing tests with Jasmine; Executing tests in the browser; Executing tests on Node.js; Other complications; Conclusion.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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.
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:
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