Ember.js 验收测试破坏了我的模型单元测试套件,ember cli 0.44
下面是如何复制。使用Ember.js 验收测试破坏了我的模型单元测试套件,ember cli 0.44,ember.js,ember-data,ember-cli,Ember.js,Ember Data,Ember Cli,下面是如何复制。使用ember cli0.44,创建一个新的应用程序,并生成用户和地址模型。它们各自属于彼此 然后,为地址编写一个单元测试,如下所示: test('it has a user', function() { var model = this.subject(); var store = this.store(); Ember.run(function() { var user = store.createRecord('user'); model.se
ember cli
0.44,创建一个新的应用程序,并生成用户
和地址
模型。它们各自属于彼此
然后,为地址
编写一个单元测试,如下所示:
test('it has a user', function() {
var model = this.subject();
var store = this.store();
Ember.run(function() {
var user = store.createRecord('user');
model.set('user', user);
ok(true);
});
});
将需要:['model:user']
添加到测试中。考试通过了
现在,键入ember g验收测试索引
。模型的单元测试在模型的右侧中断。设置行:
Died on test #1 at test (http://localhost:4200/assets/test-support.js:278:13)
at eval (ember-wtf/tests/unit/models/address-test.js:21:5)
at requireModule (http://localhost:4200/assets/vendor.js:70:29)
at http://localhost:4200/assets/test-loader.js:14:29: Assertion Failed: You can only add a 'user' record to this relationship
Source:
Error: Assertion Failed: You can only add a 'user' record to this relationship
at new Error (native)
at Error.EmberError (http://localhost:4200/assets/vendor.js:26705:23)
at Object.Ember.assert (http://localhost:4200/assets/vendor.js:16889:15)
at null.<anonymous> (http://localhost:4200/assets/vendor.js:70696:17)
at Descriptor.ComputedPropertyPrototype.set (http://localhost:4200/assets/vendor.js:25311:22)
at set (http://localhost:4200/assets/vendor.js:30004:14)
at __exports__.default.Mixin.create.set (http://localhost:4200/assets/vendor.js:44299:9)
at eval (ember-wtf/tests/unit/models/address-test.js:29:15)
at Object.Backburner.run (http://localhost:4200/assets/vendor.js:13365:27)
at apply (http://localhost:4200/assets/vendor.js:31547:27)
在测试中死亡#1在测试中死亡(http://localhost:4200/assets/test-support.js:278:13)
评估时(ember-wtf/tests/unit/models/address-test.js:21:5)
按要求(http://localhost:4200/assets/vendor.js:70:29)
在http://localhost:4200/assets/test-loader.js:14:29:断言失败:您只能将“用户”记录添加到此关系中
资料来源:
错误:断言失败:您只能将“用户”记录添加到此关系
新错误时(本机)
错误的,错误的(http://localhost:4200/assets/vendor.js:26705:23)
在Object.Ember.assert(http://localhost:4200/assets/vendor.js:16889:15)
在空
结果表明,商店引用是不同的,尽管this.store()
似乎是检索商店的好方法,但它与用于制作模型的不同:
var model = this.subject();
model.store.toString(); //<DS.Store:ember816>
this.store().toString(); //<DS.Store:ember817>
var model=this.subject();
model.store.toString()//
this.store().toString()//
因此,当我尝试使用model.set('relationship')…
时,Ember认为它不是来自同一个存储,因此断言失败
使用model.store
似乎可以做到这一点
我相信这是this.store
测试助手中的错误。对于最新版本的ember cli、ember和ember数据,这个问题没有发生。Github问题也很接近了。test runner输出是什么?@papirtiger我在跟踪中挖掘了一点。我测试中使用的store
与emb中使用的不一样er data
进行断言。Sostore.modelFor('user')的用户实例
对我的应用商店来说是正确的,但不是lib中使用的应用商店。我想知道验收测试是否会导致首先实例化不同的应用商店,如果只需要将涉及应用商店的所有测试都保持在验收测试中,那么我正在非CLI应用程序(Teaspoon 0.8.0、QUnit 1.14.0、Ember.js 1.7.0)中运行类似的测试我没有遇到同样的问题。访问存储的两种方式都会导致相同的存储对象。您也有验收测试?ember qunit的哪个版本?我也有验收测试(您的意思是与集成测试相同吗?),但它们不会直接在存储中创建模型。我使用ember qunit的最新版本,即0.1.8()。您为此提交了一个ember cli错误吗?没有,花了一点时间查找合适的位置+查找测试,但找不到。不过我需要这样做。