Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/406.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用Jasmine的示例说明_Javascript_Cucumber_Jasmine_Karma Jasmine_Gherkin - Fatal编程技术网

Javascript 使用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

在使用Jasmine时,有没有办法在规范中实现示例(或表)

我真的很喜欢Jasmine语法,但是能够定义示例我觉得更重要

我希望将以下内容移植到Jasmine:

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

好问题,我发现自己今天也在想同样的问题。