我正在尝试编写渲染 Handlebars 组件的单元测试。当测试运行时,对象是空的并且没有生成 HTML。我使用其他组件遵循了相同的布局,并且它们正确呈现。我很困惑为什么返回的对象是 null/undefined
这是我的 Ember 测试代码:
import { moduleForComponent, test } from 'ember-qunit';
import hbs from 'htmlbars-inline-precompile';
moduleForComponent('csv-upload', 'Integration | Component | csv upload', {
integration: true
});
test('it renders', function(assert) {
assert.expect(2);
this.render(hbs`{{csv-upload}}`);
assert.equal(this.$().text().trim(), '');
// Template block usage:
this.render(hbs`
{{#csv-upload}}
template block text
{{/csv-upload}}
`);
assert.equal(this.$().text().trim(), '');
});
测试的输出是:
ok 32 PhantomJS 2.1 - JSHint - integration/pods/components/csv-upload/component-test.js: should pass jshint
not ok 33 PhantomJS 2.1 - Integration | Component | device actions: it renders
---
actual: >
null
输出的另一件事:
undefined is not an object (evaluating 'this.get('selected').isAny')
最佳答案
在我们的例子中,您的组件似乎需要设置一些属性(selected
)。由于未定义,组件将无法正确呈现,从而导致测试失败。尝试将 selected
属性传递给您的组件,看看是否有帮助。
注意:这是转换为答案的原始评论。
关于javascript - Ember 单元测试渲染 Handlebars 返回 null 或 undefined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38057515/