James White
James White

Reputation: 535

Qunit: TypeError: undefined is not a function

These are the tests I've written so far. This first assertion passes. For the second I get the error: TypeError: undefined is not a function.

/*global describe, it, assert */
App.rootElement = '#emberTestingDiv';

App.setupForTesting();
App.injectTestHelpers();

module('Integration Tests', {
  setup: function() {
    App.reset();
  }
});


// Tests

test('search terms?', function() {
  App.mainSearcher.params.q = 'our keywords';
  equal(App.mainSearcher.params.q, 'our keywords');
});

test('router?', function() {
  visit('/search?q=method&sort=patAssignorEarliestExDate%20desc');
  andThen(function(){
    equal(find('title').text(), 'method');
  });
});

I'm not sure why I'm getting that. I'm using grunt-contrib-qunit so I'm curious if I did something wrong with setting qunit up with the Ember app via grunt/npm.

But I don't think that's it because the first test is passing.

I'd appreciate any help.

Thanks!

Edit:

Here's the full error

Died on test #1 at file:///Users/jwhite/Documents/workspace/uspto-aotw/front-end/test/spec/test.js:21:1: undefined is not a function
Source: TypeError: undefined is not a function

Line 21 is the first line for the second test:

test('router?', function() {

Upvotes: 1

Views: 1724

Answers (1)

Jordan Kasper
Jordan Kasper

Reputation: 13273

My guess? Something in the first test run "unsets" the global test variable/method. My recommendation is instead to use the fully qualified version of the QUnit API:

/*global describe, it, assert */
App.rootElement = '#emberTestingDiv';

App.setupForTesting();
App.injectTestHelpers();

QUnit.module('Integration Tests', {   // qualified
  setup: function() {
    App.reset();
  }
});


// Tests

QUnit.test('search terms?', function(assert) {   // qualified (with `assert` arg)
  App.mainSearcher.params.q = 'our keywords';
  assert.equal(App.mainSearcher.params.q, 'our keywords');  // qualified
});

QUnit.test('router?', function(assert) {   // qualified (with `assert` arg)
  visit('/search?q=method&sort=patAssignorEarliestExDate%20desc');
  andThen(function(){
    assert.equal(find('title').text(), 'method');   // qualified
  });
});

If that works, then my assumption is correct, but I have no idea how that could happen in your first test run since it doesn't really do anything. I suppose it could be something in App.reset(), but then why is test() defined the first time?

In any case... try the qualified method calls first, could be a quick fix.

Upvotes: 1

Related Questions