在ember-cli应用中设置集成测试——如何访问module()和visit()

Setting up integration tests in an ember-cli app - how to access module() and visit()?

本文关键字:访问 module visit 应用 ember-cli 设置 集成测试 何访问      更新时间:2023-09-26

本页,ember-cli测试,表示"包含的测试演示了如何使用新工具编写单元测试和验收/集成测试ember-testing包。"

然而,为了得到一个集成测试工作,我需要找到modulevisit或任何余烬测试助手。它们在哪里找到,我可以从哪里进口?


细节:

我发现最接近module的是moduleFor,它可以从ember-qunit导入。模块不适合集成测试,因为我正在测试应用程序中的整个页面或一系列页面,而不是单个模型,路由,控制器,视图等。

我最好的猜测是visit可以在Ember本身中找到,但我不确定从哪里导入它。

既不使用module也不使用moduleFor,我能够运行测试,但它们出错了:

ReferenceError: visit is not defined

ember-cli生成start-app.js文件,其中包含为测试准备ember的函数。

在您的集成测试文件…

import startApp from '../../helpers/start-app'; // change this due to your folder hierarchy
var App;
module('Integration Test', {
  setup: function(){
    App = startApp();
  },
  teardown: function(){
    Ember.run(App, 'destroy');
  }
}

现在你的烬应用程序准备测试。

扩展@saygun的回答。到目前为止,我们将根据需要使用moduleForComponent或moduleFor来代替module。如:

moduleForComponent('comp-name', 'Integration | Component | comp name', {
  integration: true,
  setup: function(){
    App = startApp();
  },
  teardown: function(){
    Ember.run(App, 'destroy');
  }
});