Search code examples
ember.jsember-dataember-qunit

Test non ember data models with ember qunit


I am using ember-qunit in an ember-cli application. My app is still not using ember-data for models.

The moduleForModel helper doesn't work at all. Is it required to have models extend from DS.Model to use ember-qunit?


Solution

  • Honestly the best part about testing simple models (without ember-data in the mix) is that you can new them up like plain old javascript objects.

    import { test, module } from 'qunit';
    import Foo from 'myapp/models/foo';
    
    module('my first unit test');
    
    test('do something with a computed property', function(assert) {
        var foo = new Foo();
        foo.set('id', 1);
        foo.set('first', 'toran');
        foo.set('last', 'billups');
        //or this var foo = Foo.create({id: 1, first: 'toran', last: 'billups'});
        assert.equal(foo.get('full'), 'toran billups');
    });