我有一个使用的组件this.get('model.property')
,并且它按预期工作。
对于我的集成测试,我使用 Mirage,它适用于我的所有其他测试(包括集成测试),但是当我测试这个特定组件时,我得到:
TypeError: Cannot read property 'then' of undefined
这就是我的测试的样子:
import { moduleForComponent, test } from 'ember-qunit'
import hbs from 'htmlbars-inline-precompile'
import { startMirage } from 'app/initializers/ember-cli-mirage'
import Ember from 'ember'
moduleForComponent('summary-card', 'Integration | Component | summary card', {
integration: true,
beforeEach() {
this.server = startMirage()
},
afterEach() {
this.server.shutdown()
}
})
test('it renders', function(assert) {
const customer = this.server.create('customer')
const location = this.server.create('location', { customer })
const manufacturer = this.server.create('manufacturer')
const model = this.server.create('device-model', { manufacturer })
this.server.createList('device', 5, { model, customer, location })
const loc = Ember.Object.create(location)
this.set('model', loc)
this.render(hbs`{{summary-card model=model model-name=model.name tag='location' belongs-to='customer' has-many='device'}}`);
assert.equal(this.$('h1').text().trim(), 'Location 0', 'should be titled Location 0')
});
基本上,我的summary-card.js
有这样的东西:
this.get('model.' + belongs).then(relationship => {...})
where belongs
就是任何事物的价值belongs-to
被设置为当组件被调用时。
我有点困惑,因为我传递给测试的模拟模型似乎并没有像运行时那样真正代表模型ember s
(我也将 Mirage 用于开发目的)。有什么地方可以让我了解更多有关那里到底发生了什么的信息吗?
谢谢你!
附:我也尝试过使用location
对象由以下提供server.create()
,我得到了一个略有不同的错误:
TypeError: _this.get(...).then is not a function