0

我正在尝试为我的测试创建一个助手以模拟模型。

但是,我收到以下错误:

: makeInventoryObjects 未定义

我的测试助手:

// ../tests/helpers/make-inventory-objects.js
import Ember from 'ember';

export default Ember.Test.registerAsyncHelper('makeInventoryObjects', function() {
    const inventoryObjects = [{'id': 1, 'name': 'test'}];
    return inventoryObjects;
});

我的助手中的启动应用程序包含application.injectTestHelpers();

失败的测试:

import { moduleForComponent, test } from 'ember-qunit';
import hbs from 'htmlbars-inline-precompile';
// I tried to import manually too and it did not work
// import makeInventoryObjects from '../../helpers/make-inventory-objects';

moduleForComponent('model-table', 'Integration | Component | model table', {
    integration: true
});

test('it renders', function(assert) {
    this.set('inventoryResult', makeInventoryObjects());
    this.render(hbs`{{model-table inventoryResult}}`);
    assert.equal(this.$().text().trim(), '');
});   

每当我添加导入的注释时,我都会收到此错误:

: _frontendTestsHelpersMakeInventoryObjects["default"] 不是函数

4

1 回答 1

0

我所做的失败的主要原因是因为我试图在 startApp 中初始化帮助程序,而这仅用于acceptance test,而不是integration test.

我不得不将我的助手重写为:

// ../tests/helpers/make-inventory-objects.js
export default function makeInventoryObjects() {
    const inventoryObjects = [{'id': 1, 'name': 'test'}];
    return inventoryObjects;
});

然后使用注释行导入我的测试。

另外,作为旁注,如果我在做验收测试.jshintrc,我错过了添加我的测试助手。因此,验收测试也是错误的。

于 2016-12-12T18:13:20.210 回答