Javascript 使用Jasmine的示例说明
在使用Jasmine时,有没有办法在规范中实现示例(或表) 我真的很喜欢Jasmine语法,但是能够定义示例我觉得更重要 我希望将以下内容移植到Jasmine:Javascript 使用Jasmine的示例说明,javascript,cucumber,jasmine,karma-jasmine,gherkin,Javascript,Cucumber,Jasmine,Karma Jasmine,Gherkin,在使用Jasmine时,有没有办法在规范中实现示例(或表) 我真的很喜欢Jasmine语法,但是能够定义示例我觉得更重要 我希望将以下内容移植到Jasmine: Scenario Outline: eating Given there are <start> cucumbers When I eat <eat> cucumbers Then I should have <left> cucumbers Examples: | star
Scenario Outline: eating
Given there are <start> cucumbers
When I eat <eat> cucumbers
Then I should have <left> cucumbers
Examples:
| start | eat | left |
| 12 | 5 | 7 |
| 20 | 5 | 15 |
场景大纲:吃
因为有黄瓜
当我吃黄瓜的时候
那我应该吃黄瓜
示例:
|开始|吃|左|
| 12 | 5 | 7 |
| 20 | 5 | 15 |
您可以像这样使用茉莉花:
describe("Eating - Table like Tests", function () {
// the test cases
var testCasesTable = [[12, 5, 7], [20, 5, 15], [7, 3, 4]];
// the tested function - should be in a seperate file
var eating = function (start, eat) {
return start - eat;
};
// the test function
var eatingTest = function (start, eat, left) {
it('Given there are ' + start + ' cucumbers, When I eat ' + eat + ' cucumbers, Then I should have ' + left + ' cucumbers', function () {
expect(eating(start, eat)).toBe(left);
});
};
// the loop function that goes over the test cases and run them
testCasesTable.forEach(function (testCase) {
eatingTest(testCase[0], testCase[1], testCase[2]);
}
);
});
好问题,我发现自己今天也在想同样的问题。