gpt4 book ai didi

unit-testing - Ember 测试 : Cannot read property 'createRecord' of null

转载 作者:行者123 更新时间:2023-12-04 21:41:16 24 4
gpt4 key购买 nike

看来 store在我的 Ember 测试中不可用,无论是在 ObjectController 的上下文中。或在任何单元测试中。我的单元测试:

`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)
)

测试将给出:

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



谁能解释为什么我无法访问 DS来自我的测试或 Controller 本身(运行测试时)的功能?

最佳答案

因为 ember-qunit 不会将 store 注入(inject)到您的 Controller 中,所以它用于单元测试,而不是集成测试。 Ember Data 的存储超出了该 Controller 的范围。

关于unit-testing - Ember 测试 : Cannot read property 'createRecord' of null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25704396/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com