Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ember Testing: Cannot read property 'createRecord' of null

It appears that store is not available in my Ember tests, whether in the context of an ObjectController or within any unit tests. My unit test:

`import {test, moduleFor} from "ember-qunit"`
`import DS from "ember-data"`

moduleFor "controller:register", "RegisterController", {
}

test "store is working", ->
    expect 1
    controller = @subject()
    Ember.run(->
        sampleUser = controller.get("store").createRecord("user", {
            username: "myuser"
            password: "otherpassword"
        })
        ok(sampleUser instanceof DS.Model)
    )

The test will give:

Died on test #1 at test (http://localhost:4200/assets/vendor.js:73539:13) at eval (app/tests/unit/controllers/register-test.js:19:5) at requireModule (http://localhost:4200/assets/vendor.js:54:29) at http://localhost:4200/assets/test-loader.js:14:29: Cannot read property 'createRecord' of null

Can anyone explain why I am not able to access DS capabilities from either within my tests or from within the controller itself (when running tests)?

like image 782
user1429980 Avatar asked Nov 11 '22 02:11

user1429980


1 Answers

Because ember-qunit doesn't inject the store into your controllers, it's meant for unit tests, not integration tests. And Ember Data's store is outside of the scope of that controller.

like image 168
Kingpin2k Avatar answered Nov 15 '22 10:11

Kingpin2k