javascript - Ember 单元测试渲染 Handlebars 返回 null 或 undefined

标签 javascript unit-testing ember.js

我正在尝试编写渲染 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/

相关文章:

javascript - react-router-dom NavLink isActive 效果不佳

javascript - 使用 PKCS1-V1_5 (JavaScript) 加密的 RSA

javascript - 状态更新后 react 不重新渲染DOM

java - 是否可以使用 Spock stub 或模拟 SocketChannel?

android - 如何用IDEA+Gradle+Android运行单元测试

visual-studio - 强制MSTest使用单个线程

javascript - 将 Rails 路线映射到 Ember 路线

html - Ember.js 身份验证、推送状态和路由

php - 代码点火器输入

ember.js - Ember 数据 : A data hash was loaded . .. 但没有提供主键 'undefined'