黄瓜JS可以看到我的功能,但似乎没有运行这些步骤
Cucumber JS can see my feature, but doesn't seem to run the steps
我已经在我的解决方案中设置了Cucumber-JS和Grunt-JS。
我的文件夹结构如下所示:
+ Project
+ features
- Search.feature
+ step_definitions
- Search_steps.js
+ support
- world.js
- package.json
- gruntfile.js
我在gruntfile中添加了一个Cucumber-JS任务.js:
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
cucumberjs: {
src: 'features',
options: {
steps: 'features/step_definitions',
format: 'pretty'
}
}
});
grunt.loadNpmTasks('grunt-cucumber');
grunt.registerTask('default', ['cucumberjs']);
我已经写出了我的功能文件:
Feature: Search
As a user of the website
I want to search
So that I can view items
Scenario: Searching for items
Given I am on the website
When I go to the homepage
Then I should see a location search box
还有我的步骤定义文件:
var SearchSteps = module.exports = function () {
this.World = require('../support/world').World;
this.Given('I am on the website', function(callback) {
callback.pending();
});
this.When('I go to the homepage', function (callback) {
callback.pending();
});
this.Then('I should see a location search box', function (callback) {
callback.pending();
});
};
还有我的世界.js文件:
var World = function (callback) {
callback(this);
};
exports.World = World;
但是当我在命令行运行 grunt 时,虽然它似乎可以看到我的功能,但它似乎从未运行任何步骤。
我得到的只是这个:
Running "cucumberjs:src" (cucumberjs) task
Feature: Search
Scenario: Searching for items
Given I am on the website
When I go to the homepage
Then I should see a location search box
1 scenario (1 pending)
3 steps (1 pending, 2 skipped)
Done, without errors.
黄瓜似乎没有注意我在测试中放了什么。
即使我放了一些明显的逻辑错误,例如:
this.Given('I am on the website', function(callback) {
var x = 0 / 0;
callback.pending();
});
它只是忽略它并打印上述消息。
我似乎可以从 Cucumber 中获取任何错误的唯一方法是在步骤文件中放置一个彻头彻尾的语法错误。 例如,删除右括号。然后我得到这样的东西:
Running "cucumberjs:src" (cucumberjs) task
C:'dev'Project'features'step_definitions'Search_steps.js:14
};
^
Warning: Unexpected token ; Use --force to continue.
Aborted due to warnings.
我在这里错过了什么?
正如我在评论中所说,一切都按预期工作。调用callback.pending()
告诉 Cucumber 您的步骤定义尚未准备就绪,其余方案暂时应忽略。
将其更改为callback()
以告诉 Cucumber 转到方案中的下一步。如果你想通知Cucumber失败,将错误传递给该回调或抛出异常(我不建议这样做):
callback(new Error('This is a failure'));
呵呵。
你试过这个吗?
this.World = require("../support/world.js").World;
相关文章:
- 如何使用Gmail运行.js文件
- 当运行JS函数时,如何在c#中的Edgejs中获取错误文本
- 按钮未运行为按钮,找不到如何使运行JS文件
- 在单独的上下文中运行 js 代码并访问其全局变量
- 如何使用 GetValues 使用 Jint 运行 Js 代码
- 节点webkit仅运行.js文件
- 如何在Jasmine中运行js函数
- Ubuntu试图运行.js文件得到抛出错误;
- 在pink-in上运行js;在pink-out上运行不同的js
- 加载图像后运行JS
- 从命令行运行JS文件
- 如何在命令提示符下运行js文件
- Meteor/Iron路由器-何时何地运行JS以交换到所见即所得
- 按顺序运行Js代码
- 在终端中使用imacros运行JS
- 无法在 Windows 上的节点中运行.js文件
- 如何使用 Muse 参数进行布尔比较以运行 JS 函数
- 运行 JS 对象列表
- 防止动画多次运行 - js 回调
- 从子窗口的父窗口运行JS函数