Abraham P
Abraham P

Reputation: 15471

Karma e2e test fails with typerror

I have a fairly minimalistic app ( a single Controller, three directives) defined under app/scripts.

When karma is run with karma start, and I navigate to localhost:9100, the unit tests run. However, when I run with karma start karma-2e2.conf.js, the run errors out with:

    [31mChrome 27.0 (Mac) I haz all the things I haz grid FAILED[39m
TypeError: Cannot read property 'name' of undefined
    Chrome 27.0 (Mac): Executed 1 of 1[31m (1 FAILED)[39m


My tests live under test/e2e/spec/*.js

My karma-e2e.conf.js reads as follows:

     basePath = '';

    files = [
      ANGULAR_SCENARIO,
      ANGULAR_SCENARIO_ADAPTER,
     'app/components/jquery/jquery.js',
     'app/components/angular/angular.js',
     'test/e2e/**/*.js'
    ];

    proxies = {
      '/' : 'http://localhost:9000'
    }
    exclude = [];

    reporters = ['progress'];

    port = 8080;

    runnerPort = 9100;
    colors = true;

    logLevel = LOG_INFO;

    autoWatch = false;

    browsers = ['Chrome'];

    captureTimeout = 5000;

    singleRun = false;

My test is:

 describe('I haz all the things', function(){
   beforeEach(function(){
     browser().navigateTo('/');
   });

  it('I haz grid', function(){
    expect(angular.element('div.grid-item').count).toEqual(1);
  });
  });

Why is it failing and how can I fix it?

Upvotes: 1

Views: 1309

Answers (1)

Karen Zilles
Karen Zilles

Reputation: 7661

Your syntax on the test is wrong

It needs to be:

expect(repeater('div.grid-item').count()).toEqual(1);

Read up on the e2e domain specific language... It is not angular or jquery, it's a little mysterious, but powerful.

To better debug e2e tests, use a test runner instead of using Karma. This is the file called runner.html included with the angular-seed starter app:

<!doctype html>
<html lang="en">
  <head>
    <title>End2end Test Runner</title>
    <script src="../lib/angular/angular-scenario.js" ng-autotest></script>
    <script src="scenarios.js"></script>
  </head>
  <body>
  </body>
</html>

Just navigate to runner.html in your browser and it starts running your tests in front of you, just refresh to rerun. You can add a pause() to your tests and the test will stop at that point and prompt you to continue. You can use firebug or another debugger to look at the state of the app.

Upvotes: 3

Related Questions