繁体   English   中英

Cucumber 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.js中添加了一个Cucumber-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();
    });
};

还有我的world.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'));

HTH。

你有尝试过吗?

this.World = require("../support/world.js").World; 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM