我在试着让吉格斯和弗里斯比一起工作。我们使用Frisby作为黑箱测试在API上运行功能测试。最近将Frisby升级到2.0.8版本,该版本现在使用Jest。一切都很好。现在,我想在顶部添加量规-js,以添加人类可读的测试规范/场景/步骤。
我正在Windows8.1机器上进行测试:
为了使其工作,我添加了Frisby作为一个依赖关系,以衡量-js。现在它部分起作用了。它实际上执行了测试步骤,但是失败了
ReferenceError: expect is not defined
at incrementAssertionCount (C:\Users\<USER>\AppData\Roaming\gauge\plugins\js\2.0.3\node_modules\frisby\src\frisby\expects.js:14:20)
at FrisbySpec.status (C:\Users\<USER>\AppData\Roaming\gauge\plugins\js\2.0.3\node_modules\frisby\src\frisby\expects.js:23:5)
at FrisbySpec._addExpect.e (C:\Users\<USER>\AppData\Roaming\gauge\plugins\js\2.0.3\node_modules\frisby\src\frisby\spec.js:396:23)
at FrisbySpec._runExpects (C:\Users\<USER>\AppData\Roaming\gauge\plugins\js\2.0.3\node_modules\frisby\src\frisby\spec.js:288:24)
at _fetch.fetch.then.then (C:\Users\<USER>\AppData\Roaming\gauge\plugins\js\2.0.3\node_modules\frisby\src\frisby\spec.js:142:14)
at process._tickCallback (internal/process/next_tick.js:109:7)下面是实际的测试步骤:
/* globals gauge*/
"use strict";
var frisby = require('frisby');
// --------------------------
// Gauge step implementations
// --------------------------
step("Get responds with <state>.", function (state, doneFn) {
frisby
.timeout(1500)
.get('http://localhost:8001/some/get/resource', {
headers: {
'Content-Type': 'application/json',
'Authorization': 'Basic QWERTYASDFEDEFTGHYFVCCFRJgyuku'
}
})
// .expect('status', 200)
// .expect('header', 'Content-Type', 'application/json; charset=utf-8')
// .expect('json', state)
.done(doneFn).catch(error => {
console.log(error);
});
});当注释出行未注释时,就会发生错误。
我认为问题实际上在于它是如何依赖负载的,但我的js知识有点支离破碎和生疏。任何帮助都将不胜感激。
发布于 2017-11-27 22:57:00
我找到了更好的解决原来问题的办法。当我开始实现@duyker建议的时候。我注意到(最后) Frisby代码有意忽略对Jasmine的依赖,如果它不存在,但是有一个bug。所以我提交了一个修好它。它被接受了。
现在问题解决了,Frisby可以不用茉莉花或小丑工作了。
发布于 2017-11-23 12:33:57
.expect(...)函数未定义的原因是,frisby期望jasmine是测试运行程序,而jasmine的expect函数可供其使用。
所有frisby包含的expect函数都执行下面的"incrementAssertionCount“。因为它无法在expect中找到if (_.isFunction(expect)),所以它无法提供frisby提供的默认期望。
function incrementAssertionCount() {
if (_.isFunction(expect)) { // FAILS HERE: 'expect' does not exist
// Jasmine
expect(true).toBe(true);
}
}看起来有一个简单的替代方法,就是将frisby的expect函数复制到您的代码中,并调用addExpectHandler方法(更好的是,创建一个可以引用的外部包,这样您就不必将其复制到每个项目中)。
下面是一个简单的例子:
var frisby = require("frisby");
var assert = require("assert");
function statusHandler(response, statusCode) {
assert.strictEqual(response.status, statusCode, `HTTP status ${statusCode} !== ${response.status}`);
}
beforeScenario(function () {
frisby.addExpectHandler('status', statusHandler);
});
step("Call httpbin.org and get a teabot", function (done) {
frisby.get('http://httpbin.org/status/418')
.timeout(2000)
.expect('status', 418)
.catch(function (e) {
done(e);
})
.done(done);
});https://stackoverflow.com/questions/47384234
复制相似问题