ember.js - Ember cli mirage:在验收测试中使用夹具
问题描述
我正在尝试在我的验收测试中使用固定装置,但是由于重复数据,它会导致测试失败,因为每次测试都会将固定装置重新插入海市蜃楼数据库中。有没有办法解决这个问题或在每次测试时移除固定装置
setupApplicationTest(hooks);
setupMirage(hooks);
hooks.beforeEach(function() {
this.server.loadFixtures();
});
解决方案
您在上面向我展示的这段代码来自哪里?
在验收测试中,Mirage 自动从它捆绑在其插件中的初始化程序启动/停止服务器addon/instance-initializers/ember-cli-mirage-autostart.js
:
let server = startMirage(appInstance);
testContext.server = server;
// To ensure that the server is shut down when the application is
// destroyed, register and create a singleton object that shuts the server
// down in its willDestroy() hook.
appInstance.register('mirage:shutdown', MirageShutdown);
调用:
willDestroy() {
let testContext = this.get('testContext');
testContext.server.shutdown();
delete testContext.server;
}
Ember 在每次测试之间启动和停止应用程序,这意味着每次验收测试都会自动从空数据库开始。
如果您不在验收测试的范围内,则需要先停止自己。
// tests/integration/components/your-test.js
import { startMirage } from 'yourapp/initializers/ember-cli-mirage';
moduleForComponent('your-component', 'Integration | Component | your component', {
integration: true,
beforeEach() {
this.server = startMirage();
},
afterEach() {
this.server.shutdown();
}
});
每次测试后调用关机对于清除数据至关重要
推荐阅读
- python - 在 Counters 的命名元组上创建一个抽象类
- c++ - 二进制“==”:未找到采用“Enemy”类型的左操作数的运算符(或没有可接受的转换)
- php - 如何通过两个 AND 条件过滤一列?
- jquery - 有没有类似这个滚动效果的 jQuery 或 CSS 滑块?
- bash - 如何使 bash 命令可以从 Windows 中的任何目录执行?
- java - Spring Reactive Webflux 微服务的多重认证策略
- sql - Get-AzureADUser - ALL - PowerShell Slow 获取所有用户和对帐户进行更改的用户
- php - 如何从mysql更改为mysqli
- jquery - ASP Net Core AJAX 将 NULL 发送到控制器
- curl - 如何使用 curl --upload-file 上传 2 个文件