4

I'm testing my AngularJS app with Jasmine at the moment, and it's passing specs. I tried to run the tests with Karma, and it's failing. It appears that Karma can't see the $scope being defined in the Jasmine spec, but the Jasmine runner sees it fine.

My karma.conf.js:

frameworks = ['jasmine'];
colors = true;
singleRun = true;
files = [
    JASMINE,
    JASMINE_ADAPTER,
    ANGULAR_SCENARIO,
    ANGULAR_SCENARIO_ADAPTER,
    'lib/jquery-1.9.1.min.js',
    'lib/angular.min.js',
    'lib/angular-mocks.js',
    'lib/jquery.scrollTo.js',
    'lib/jquery-ui.min.js',
    'lib/calendar.js',
    'lib/date.js',
    'src/app.js',
    'spec/*.spec.js'
];
browsers = [
    'PhantomJS',
    'Firefox'
];

My test.spec.js:

describe('Application startup', function(){
    beforeEach(module('app'));
    describe('MainCtrl', function(){
        var scope, ctrl;
        beforeEach(inject(function($rootScope, $controller){
            scope = $rootScope.$new();
            ctrl = $controller('MainCtrl', {
                $scope: scope
            });
        }));
        it("should initialize $scope.testLoad to 42", function(){
            expect(scope.testLoad).toBe(42);
        });
});
});

The output I'm getting:

expect undefined toBe 42

As Jasmine is passing this with no problems, it's obviously either Karma or my config file. What's going on?

4
  • I removed ANGULAR_SCENARIO and ANGULAR_SCENARIO_ADAPTER and it's running fine now. Found the appropriate docs. Made a bad assumption. Commented May 21, 2013 at 2:19
  • 2
    This is because ANGULAR_SCENARIO is intended for e2e tests and this require a separate karma.conf file from the one you are using for unit tests Commented May 22, 2013 at 0:47
  • Where are the docs located for using all of these together? Commented Sep 28, 2013 at 2:50
  • @andy If you've answered your own question, please submit the solution as an actual answer. That way, this question won't show up in the 'unanswered' section ;-) Commented Apr 8, 2014 at 23:30

1 Answer 1

1

I removed ANGULAR_SCENARIO and ANGULAR_SCENARIO_ADAPTER and it's running fine now. Found the appropriate docs. Made a bad assumption.

Thanks to @canotto90 and @Tyler Eich for help and clarification.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.