我一直在尝试使用ES6断言和Nightmare.js来加载测试页面来测试我的磁带代码。我一直在尝试不同的ES6方法:异步/等待、屈服、生成器,我想我有点过头了。我也不确定何时何时不使用巴贝尔磁带。我可以通过下面的测试,但一旦创建了另一个计算方法,就会将错误排除在外。文档相当稀少(或使用Mocha)。这里的最佳做法是什么?
import {test} from "tape";
import {default as nightmare} from "nightmare";
const page = nightmare().goto("http://localhost:4000/index.html");
page.evaluate(() => document.getElementsByTagName("body").length).end()
.then((result) => {
test("detect page body", (assert) => {
assert.equal(1, result);
assert.end();
});
});ps。我使用巴贝尔带流道来运行测试。
发布于 2016-02-29 17:31:56
我可以通过下面的测试,但一旦创建了另一个计算方法,就会将错误排除在外。
嗯,你在噩梦实例上打电话给.end()。一旦实例结束,您就不应该与其交互,这可能会导致您的一些问题。
文档相当稀少(或使用Mocha)
如果您查看梦魇中的测试套件,describe块有一个beforeEach和afterEach,它们分别设置或销毁噩梦实例。您的测试--至少在我的阅读中--将为您的所有测试设置一个噩梦实例,这可能会导致不良行为。
尽管如此,您可能想尝试将梦魇的声明和用法移到测试的内部。戴上手铐,就像:
import {test} from "tape";
import {default as Nightmare} from "nightmare";
test('detect page body', (assert) => {
var nightmare = Nightmare();
nightmare
.goto("http://localhost:4000/index.html")
.evaluate(() => document.getElementsByTagName("body").length)
.then((result) => {
assert.equal(1, result);
nightmare.end(()=>{
assert.end();
});
});
});https://stackoverflow.com/questions/35691806
复制相似问题