【问题标题】:My jest-cucumber test does not recognise my step definitions我的 jest-cucumber 测试无法识别我的步骤定义
【发布时间】:2021-09-06 08:44:55
【问题描述】:

我正在使用这个库 https://www.npmjs.com/package/jest-cucumber 以 BDD 格式运行我的笑话测试。

每当我运行示例测试时,我都会得到:

? Given Test for given step
       Undefined. Implement with the following snippet:

         Given('Test for given step', function () {
           // Write code here that turns the phrase above into concrete actions
           return 'pending';
         });
       
   ? When Test for when step
       Undefined. Implement with the following snippet:

         When('Test for when step', function () {
           // Write code here that turns the phrase above into concrete actions
           return 'pending';
         });
       
   ? Then Test for then step
       Undefined. Implement with the following snippet:

         Then('Test for then step', function () {
           // Write code here that turns the phrase above into concrete actions
           return 'pending';
         });
       

1 scenario (1 undefined)
3 steps (3 undefined)
0m00.000s

Process finished with exit code 1

这是文件所在的文件夹:

我的 BDD 场景:

Feature: E2E Tests

Scenario:Example
  Given Test for given step
  When Test for when step
  Then Test for then step

我的步骤定义代码:

import { loadFeature, defineFeature } from 'jest-cucumber';
const feature = loadFeature('/src/smokeTests/smokeTests.feature');

defineFeature(feature, (test) => {
    test('Example', ({ given, when, then }) => {
        let x: number;
        let z: number;

        given('Test for given step', () => {
            x = 1;
        });

        when('Test for when step', () => {
            z = x + 3;
        });

        then('Test for then step', () => {
            expect(z).toBe(4);
        });
    });
});

没有其他的想法了!

【问题讨论】:

    标签: typescript cucumber ts-jest


    【解决方案1】:

    将步骤定义文件重命名为 *.step.ts

    【讨论】:

    • 正如目前所写,您的答案尚不清楚。请edit 添加其他详细信息,以帮助其他人了解这如何解决所提出的问题。你可以找到更多关于如何写好答案的信息in the help center
    猜你喜欢
    • 1970-01-01
    • 2021-11-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-07
    • 2012-10-18
    • 2019-05-20
    • 1970-01-01
    相关资源
    最近更新 更多