admin管理员组文章数量:1418103
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
2 Answers
Reset to default 5As 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;
本文标签: javascriptCucumber JS can see my featurebut doesn39t seem to run the stepsStack Overflow
版权声明:本文标题:javascript - Cucumber JS can see my feature, but doesn't seem to run the steps - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745269570a2650807.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论