javascript - Cucumber JS can see my feature, but doesn't seem to run the steps - Stack Overflow

I've set up Cucumber-JS and Grunt-JS within my solution.My folder structure looks like this:+ Proj

I've set up Cucumber-JS and Grunt-JS within my solution.

My folder structure looks like this:

+ Project
  + features
    - Search.feature
    + step_definitions
      - Search_steps.js
    + support
      - world.js
  - package.json
  - gruntfile.js

I've added a Cucumber-JS task in gruntfile.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']);

And I've written out my feature file:

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

And my step definition file:

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();
    });
};

And my world.js file:

var World = function (callback) {
    callback(this);
};

exports.World = World;

But when I run grunt at the mand-line, while it seems to see my features, it never seems to run any of the steps.

All I get is this:

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.

Cucumber doesn't seem to pay any attention to what I put inside the tests.

Even if I put some obvious logical bug in, e.g.:

this.Given('I am on the website', function(callback) {
    var x = 0 / 0;
    callback.pending();
});

It just ignores it and prints the above message.

The only way I can seem to get any error out of Cucumber is to put an outright syntax error in the step file. E.g. remove a closing bracket. Then I get something like this:

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.

What am I missing here?

I've set up Cucumber-JS and Grunt-JS within my solution.

My folder structure looks like this:

+ Project
  + features
    - Search.feature
    + step_definitions
      - Search_steps.js
    + support
      - world.js
  - package.json
  - gruntfile.js

I've added a Cucumber-JS task in gruntfile.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']);

And I've written out my feature file:

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

And my step definition file:

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();
    });
};

And my world.js file:

var World = function (callback) {
    callback(this);
};

exports.World = World;

But when I run grunt at the mand-line, while it seems to see my features, it never seems to run any of the steps.

All I get is this:

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.

Cucumber doesn't seem to pay any attention to what I put inside the tests.

Even if I put some obvious logical bug in, e.g.:

this.Given('I am on the website', function(callback) {
    var x = 0 / 0;
    callback.pending();
});

It just ignores it and prints the above message.

The only way I can seem to get any error out of Cucumber is to put an outright syntax error in the step file. E.g. remove a closing bracket. Then I get something like this:

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.

What am I missing here?

Share Improve this question edited Nov 18, 2013 at 0:32 Jonathan asked Nov 12, 2013 at 1:47 JonathanJonathan 32.9k40 gold badges143 silver badges209 bronze badges 4
  • Could you show us the content of your world file? You might have forgotten to call back in its constructor. – jbpros Commented Nov 15, 2013 at 8:44
  • @jbpros, I've updated the question to include the world.js file and the code that "require"s it. And yes, it does call back the constructor, but unfortunately still doesn't work. – Jonathan Commented Nov 18, 2013 at 0:34
  • 1 Everything is running smoothly, actually. You call callback.pending() in your first step definition, telling cucumber you're not finished implementing it. Look at the output, it says there was one pending step and two skipped. – jbpros Commented Nov 18, 2013 at 11:59
  • You need to call callback() instead. Pass it an error when you want Cucumber to report an error: callback(new Error('I fail!')). – jbpros Commented Nov 18, 2013 at 12:01
Add a ment  | 

2 Answers 2

Reset to default 5

As I said in my ments, everything is working as expected. Calling callback.pending() tells Cucumber your step definition is not ready yet and the rest of the scenario should be ignored for now.

Change that to callback() to tell Cucumber to move to the next step in the scenario. If you want to notify Cucumber of a failure, pass an error to that callback or throw an exception (I don't remend that though):

callback(new Error('This is a failure'));

HTH.

Have you tried this?

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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745269571a4619662.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信