Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with jasmine adapter ? #486

Closed
sabarasaba opened this issue Apr 10, 2013 · 11 comments
Closed

Problem with jasmine adapter ? #486

sabarasaba opened this issue Apr 10, 2013 · 11 comments

Comments

@sabarasaba
Copy link

Hey! I created a new project with require and jasmine, but karma keeps throwing me this error and I dont really know where else to look. Maybe you guys can help me out. So the error that im getting is:

PhantomJS 1.9 (Mac) ERROR
    TypeError: 'null' is not an object (evaluating 'spec.results_.failedCount')
    at http://localhost:9876/adapter/jasmine.js?1365618461000:67
PhantomJS 1.9 (Mac): Executed 1 of 2 ERROR (0.294 secs / 0.001 secs)

And the spec that im executing is pretty simple:

define(
  [
  ],
  function() {
    'use strict';

    describe('simple implementation', function() {
      it('should be true', function(){
        expect('do y').toBe('do y');
      });

      it('should be true again', function(){
        expect('do x').toBe('do x');
      });

    });
  }
);

And my karma.conf looks like this:

basePath = '.';

files = [
  JASMINE,
  JASMINE_ADAPTER,
  REQUIRE,
  REQUIRE_ADAPTER,

  { pattern: "libs/jquery/jquery.js", included: false },
  { pattern: "libs/require/require.js", included: false },
  { pattern: "libs/underscore/lodash.js", included: false },
  { pattern: "libs/backbone/backbone.js", included: false },
  { pattern: "libs/handlebars/handlebars.js", included: false },
  { pattern: "app/**/*.js", included: false },

  { pattern: "app/templates/*.hbs", included: false },
  { pattern: 'app/test/specs/**/*.spec.js', included: false},

  "app/test/spec-main.js"
];

exclude = [

];

reporters = ['progress'];

port = 9876;

runnerPort = 9100;

colors = true;

logLevel = LOG_ERROR;

autoWatch = true;

browsers = ['PhantomJS'];

captureTimeout = 60000;

singleRun = false;

Thanks!

Update: If I change the browsers property to 'Chrome' in the chrome console I get:

SUCCESS simple implementation should be true
SUCCESS simple implementation should be true again
@vojtajina
Copy link
Contributor

Weird, I have no idea. The error says, that Jasmine passed a spec object
with results property null, but not sure how can this happen...

Can you go to http://localhost:9876/debug.html and see if there is any
error in the console ?
Try to hack with the adapter as well (it's
/karma/adapter/jasmine.js) and try to
console.log(spec); in
https://github.com/karma-runner/karma/blob/stable/adapter/jasmine.src.js#L60to
see what is passed in...

V.

On Wed, Apr 10, 2013 at 12:03 PM, Ignacio Rivas notifications@github.comwrote:

Hey! I created a new project with require and jasmine, but karma keeps
throwing me this error and I dont really know where else to look. Maybe you
guys can help me out. So the error that im getting is:

PhantomJS 1.9 (Mac) ERROR
TypeError: 'null' is not an object (evaluating 'spec.results_.failedCount')
at http://localhost:9876/adapter/jasmine.js?1365618461000:67
PhantomJS 1.9 (Mac): Executed 1 of 2 ERROR (0.294 secs / 0.001 secs)

And the spec that im executing is pretty simple:

define(
[
],
function() {
'use strict';

describe('simple implementation', function() {
  it('should be true', function(){
    expect('do y').toBe('do y');
  });

  it('should be true again', function(){
    expect('do x').toBe('do x');
  });

});

});

And my karma.conf looks like this:

basePath = '.';

files = [
JASMINE,
JASMINE_ADAPTER,
REQUIRE,
REQUIRE_ADAPTER,

{ pattern: "libs/jquery/jquery.js", included: false },
{ pattern: "libs/require/require.js", included: false },
{ pattern: "libs/underscore/lodash.js", included: false },
{ pattern: "libs/backbone/backbone.js", included: false },
{ pattern: "libs/handlebars/handlebars.js", included: false },
{ pattern: "app/*/.js", included: false },

{ pattern: "app/templates/.hbs", included: false },
{ pattern: 'app/test/specs/__/
.spec.js', included: false},

"app/test/spec-main.js"
];

exclude = [

];

reporters = ['progress'];

port = 9876;

runnerPort = 9100;

colors = true;

logLevel = LOG_ERROR;

autoWatch = true;

browsers = ['PhantomJS'];

captureTimeout = 60000;

singleRun = false;

Thanks!


Reply to this email directly or view it on GitHubhttps://github.com//issues/486
.

@sabarasaba
Copy link
Author

After a few hours debugging, i realized that i had a problem with my spec-main.js file. It's working now! 💃

@FabienDeshayes
Copy link

Hi @sabarasaba, It seems that I encounter the same problem, only that it happens when I'm using Squire.js with it. Could you tell us what was wrong in your spec-main.js file?

@sabarasaba
Copy link
Author

I dont really remember what was it, it think it was a problem with the function that returns the spec-files. Heres what we're doing now in our spec-main.js:

var tests = Object.keys(window.__karma__.files).filter(function (file) {
  return /spec\.js$/.test(file);
});

requirejs.config({
    // Karma serves files from '/base'
    baseUrl: '/base/www/js',

    paths: {
      'jquery' : 'vendor/jquery/jquery-1.9.1',
      'underscore' : 'vendor/underscore/lodash',
      'backbone' : 'vendor/backbone/backbone',
      'handlebars' : 'vendor/handlebars/handlebars',
      'i18next' : 'vendor/i18next/i18next.amd.withJQuery',
      'postal' : 'vendor/postal/postal'
    },

    shim: {
      'backbone': {
        deps: ['underscore', 'jquery'],
        exports: 'Backbone'
      },
      'handlebars': {
        exports : 'Handlebars'
      }
    },

    // ask Require.js to load these files (all our tests)
    deps: tests,

    // start test run, once Require.js is done
    callback: window.__karma__.start
  });

Regards.

@FabienDeshayes
Copy link

Well it seems I've got the same sort of config. Thanks for the help! I'll probably raise an issue onto Squire.js as it seems to be the cause.

@kwal
Copy link

kwal commented Apr 30, 2013

@FabienDeshayes were you able to resolve this? I'm running into the same issue while trying to use Squire.

@FabienDeshayes
Copy link

Yes, I fixed it. Basically as I'm using Require.js I had to change my test-main.js: instead of defining deps and callback in the require config, I added the following bit add the end of test-main:

require(tests, function() {
    window.__karma__.start();
});

For info, my test looks like that:

define(['Squire'], function(Squire) {
    describe('Food', function() {
        var async = new AsyncSpec(this);
        var injector = new Squire();
        var food;
        async.beforeEach(function(done) {
            injector
                .mock('nutrient', 'fat')
                .require(['food'], function(module) {
                    food = module;
                    done();
                });
        });

        it("should have fat", function() {
            // expects...
        });

        it("should be a pizza", function() {
            // expects...
        });

        afterEach(function() {
            injector.clean('nutrient');
        });

    });

});

@deblauwetom
Copy link

Hello,

I had the same problem, and the real solution for me was that the filter was not ok: the regular expression also included the initial boot file, in your example "test-main.js". So when making sure this was not added to the "deps" it worked.

@hgcummings
Copy link

Yes, I fixed it. Basically as I'm using Require.js I had to change my test-main.js: instead of defining deps and callback in the require config, I added the following bit add the end of test-main:

Thanks! I had the exact same problem (using karma, jasmine, require.js, and squire) and this fix worked for me. Does anyone have any idea what the underlying issue is here?

@aleksandrj1
Copy link

JASMINE is not defined

@maksimr
Copy link
Contributor

maksimr commented Mar 9, 2015

@aleksandrj1 JASMINE variable was removed, use frameworks.
Example is described in documentation

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants