feat(data_table): add support to cucumberjs

This commit is contained in:
abraaoalves
2016-09-04 22:22:59 -03:00
parent 084e559166
commit 1136e3f00c
2 changed files with 54 additions and 5 deletions
+44 -4
View File
@@ -1,24 +1,26 @@
/// <reference path="cucumber.d.ts" />
/// <reference path="../assert/assert.d.ts" />
function StepSample() {
type Callback = cucumber.CallbackStepDefinition;
type Table = cucumber.TableDefinition;
var step = <cucumber.StepDefinitions>this;
var hook = <cucumber.Hooks>this;
hook.Before(function(scenario, callback){
scenario.isFailed() && callback.pending();
})
hook.Around(function(scenario, runScenario) {
scenario.isFailed() && runScenario(null, function(){
console.log('finish tasks');
});
});
hook.registerHandler('AfterFeatures', function (event, callback) {
callback();
});
step.Given(/^I am on the Cucumber.js GitHub repository$/, function(callback:Callback) {
this.visit('https://github.com/cucumber/cucumber-js', callback);
});
@@ -36,5 +38,43 @@ function StepSample() {
callback(new Error("Expected to be on page with title " + title));
}
});
// Type for data_table.js on
// https://github.com/cucumber/cucumber-js/blob/a5fd8251918c278ab2e389226d165cedb44df14a/lib/cucumber/ast/data_table.js
step.Given(/^a table step with Table raw$/, function(table:Table){
var expected = [
['Cucumber', 'Cucumis sativus'],
['Burr Gherkin', 'Cucumis anguria']
];
assert.deepEqual(table.raw(), expected);
});
step.Given(/^a table step with Table rows$/, function(table: Table){
var expected = [
['Apricot', '5'],
['Brocolli', '2'],
['Cucumber', '10']
];
assert.deepEqual(table.rows(), expected)
});
step.Given(/^a table step with Table rowHash$/, function(table:Table){
var expected = {
'Cucumber': 'Cucumis sativus',
'Burr Gherkin': 'Cucumis anguria'
};
assert.deepEqual(table.rowsHash(), expected)
});
step.Given(/^a table step$/, function(table:Table){
var expected = [
{'Vegetable': 'Apricot', 'Rating': '5'},
{'Vegetable': 'Brocolli', 'Rating': '2'},
{'Vegetable': 'Cucumber', 'Rating': '10'}
];
assert.deepEqual(table.hashes(), expected)
});
}
+10 -1
View File
@@ -10,8 +10,17 @@ declare namespace cucumber {
(errror?:any):void;
}
export interface TableDefinition{
raw: () => Array<any>;
rows: () => Array<any>;
rowsHash: () => {};
hashes: () => {};
}
type StepDefinitionParam = string | CallbackStepDefinition | TableDefinition;
interface StepDefinitionCode {
(...stepArgs: Array<string |CallbackStepDefinition>): PromiseLike<any> | any | void;
(...stepArgs: Array<StepDefinitionParam>): PromiseLike<any> | any | void;
}
interface StepDefinitionOptions{