question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Running Karma/Jasmine tests against code with raven-js integrated

See original GitHub issue

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 😃

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
Diannacommented, Nov 18, 2015

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.

0reactions
kylezeeuwencommented, Mar 12, 2015

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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found