我对ember社区很陌生,我创建了一个组件,可以在给定的DS.Model对象上生成其内容:
// templates/test.hbs
{{my-component model=model.model modelName=model.modelName}}
// routes/test.js
import MyModel from 'app/models/my-model
export default Ember.Route.extend({
model() {
model: MyModel,
modelName: 'my-model'
}
});
// components/my-component.js
export default Ember.Component.extend({
modelAttributes: Ember.computed(function() {
let model = this.get('model');
let attributes = [];
// retrieves options if exists
let labels = this.get('labels');
let requires = this.get('requires');
// Populating modelAttributes
model.eachAttribute((attr, meta) => {
let attributesInfo = {key: attr, type: meta.type, data: ''};
// do some stuff
attributes.push(attributesInfo);
});
return attributes;
})
});
它运作良好,但我很坚持测试它。 的确,我试过了:
// tests/acceptances/components/my-component
moduleForComponent('my-component', 'Integration | Component | my component', {
integration: true
});
const DummyModel = DS.Model.extend({
string: DS.attr('string'),
email: DS.attr('email')
});
test('it renders', function(assert) {
server.createList('dummy', 5);
this.set('modelDescription', DummyModel);
this.set('modelName', 'dummy');
this.render(hbs`{{easy-crud modelName=modelName model=modelDescription}}`);
// asserting stuff
});
并使用海市蜃楼伪造虚拟物品。但它继续失败并出现以下错误:
Died on test #1 at Module.callback (http://localhost:7357/assets/tests.js:698:24)
at Module.exports (http://localhost:7357/assets/vendor.js:123:32)
at requireModule (http://localhost:7357/assets/vendor.js:38:18)
at TestLoader.require (http://localhost:7357/assets/test-support.js:6979:7)
at TestLoader.loadModules (http://localhost:7357/assets/test-support.js:6971:14)
at Function.TestLoader.load (http://localhost:7357/assets/test-support.js:7001:22)
at http://localhost:7357/assets/test-support.js:6885:18: Unexpected token u in JSON at position 0
有没有人有想法?或者我做错了什么?
由于
编辑:为代码理解添加ember函数