Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jasmine/Karma test: browser is not defined

If this test:

'use strict'

describe('application', function() {
    it('should login', function() {
        browser().navigateTo('/');
        expect('111').toBe('111');
    });
});

includes the "browser" line, the result is:

Chrome 26.0 (Windows) application should login FAILED
    ReferenceError: browser is not defined
        at null.<anonymous> (...../test/js/e2e/tests/test.js:6:9)
Chrome 26.0 (Windows): Executed 1 of 1 (1 FAILED) (0.359 secs / 0.004 secs)

but without this line the test succeeds.

People suggest to include angular-scenario.js, but this breaks tests

expect('111').toBe('222');

is evaluated as true.

What to do?

like image 449
Paul Avatar asked Mar 24 '23 09:03

Paul


1 Answers

You need to have your app's server running along with the karma runner. So with Node.js:

node app.js

Also, make sure you change the urlRoot property in your karma config so it doesn't conflict with your app's and yes you need angular-scenario.js

files = [
  ANGULAR_SCENARIO,
  ANGULAR_SCENARIO_ADAPTER,
  'test/**/*_spec.js'
];

urlRoot = '/__karma/';

proxies = {
  '/' : 'http://localhost:3000/'
};
like image 140
Corey C Avatar answered Apr 02 '23 03:04

Corey C