Skip to content

Instantly share code, notes, and snippets.

@commadelimited
Last active August 29, 2015 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save commadelimited/11260080 to your computer and use it in GitHub Desktop.
Save commadelimited/11260080 to your computer and use it in GitHub Desktop.
Ember Qunit Testing

I'm updating my unit tests to use the new Ember-QUnit approach and I'm running into a problem with one computed property test.

I'm trying to test that hire_date returns the correct string, but the test keeps failing with undefined is not a function. I know the setup is correct because another test, location_class, works just fine.

Can anyone offer insight as to why this is failing?

Source: 	
TypeError: undefined is not a function
    at null.<anonymous> (http://0.0.0.0:8844/app/js/application.js:146:29)
    at ComputedPropertyPrototype.get (http://0.0.0.0:8844/test/packages/ember/ember.js:4951:38)
    at get (http://0.0.0.0:8844/test/packages/ember/ember.js:2176:17)
    at Ember.Observable.Ember.Mixin.create.get (http://0.0.0.0:8844/test/packages/ember/ember.js:12425:12)
    at Object.<anonymous> (http://0.0.0.0:8844/test/model-person-test-qunit.js:26:21)
    at Object.wrapper (http://0.0.0.0:8844/test/packages/ember-qunit/dist/globals/main.js:243:27)
    at Object.Test.run (http://0.0.0.0:8844/test/packages/qunit/qunit/qunit.js:1303:18)
    at http://0.0.0.0:8844/test/packages/qunit/qunit/qunit.js:1463:10
    at process (http://0.0.0.0:8844/test/packages/qunit/qunit/qunit.js:1016:24)
    at http://0.0.0.0:8844/test/packages/qunit/qunit/qunit.js:186:5
/*=================== TESTS ====================*/
emq.globalize();
App.setupForTesting();
App.injectTestHelpers();
setResolver(
Ember.DefaultResolver.create({
namespace: App
})
);
App.rootElement = '#ember-testing';
moduleForModel('person', 'Models > Person');
// this test works just fine
test('location_class is a valid computed property - non-hyphenated', function() {
var person = this.subject({
Location: 'Nashville'
});
equal(person.get('location_class'), 'nashville');
});
// this test fails
test('hire_date is a valid computed property', function() {
var person = this.subject({
Emmaversary: '9/24/2012'
});
var me = person.get('hire_date');
equal(me, 'bob');
});
App.Person = DS.Model.extend({
First: DS.attr('string'),
Last: DS.attr('string'),
Department: DS.attr('string'),
Team: DS.attr('string'),
Title: DS.attr('string'),
Location: DS.attr('string'),
Direct: DS.attr('string'),
Extension: DS.attr('string'),
Cell: DS.attr('string'),
IM: DS.attr('string'),
Email: DS.attr('string'),
Emmaversary: DS.attr('date'),
hire_date: function(){
var hire_date = this.get('Emmaversary'),
months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
day = hire_date.getDate(),
month = months[hire_date.getMonth()],
year = hire_date.getFullYear();
return '%@ %@, %@'.fmt(month, day, year);
}.property('Emmaversary'),
location_class: function(){
var location = this.get('Location');
return location.replace(' ', '-').toLowerCase();
}.property('Location')
});
@eoinkelly
Copy link

What happens if you stick a debugger statement in hire_date and have a poke around or step through it? Are all the things you are invoking i.e. anything preceeding () as expected?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment