Codr
Codr

Reputation: 57

My jest-cucumber test does not recognise my step definitions

I am using this library https://www.npmjs.com/package/jest-cucumber to run my jest tests in BDD format.

Whenever I run my sample test I get this:

? 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

This is the folder where the files live:

enter image description here

My BDD scenarios:

Feature: E2E Tests

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

My Step definition code:

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

Running out of ideas on what else to do!

Upvotes: 2

Views: 1651

Answers (2)

Qasim Ahmed
Qasim Ahmed

Reputation: 197

I think he means:

Add the following to your Jest configuration:

  "testMatch": [
    "**/*.steps.js"
  ],

As mentioned in the jest-cucumber docs https://www.npmjs.com/package/jest-cucumber.

Upvotes: 0

Michael
Michael

Reputation: 11

Rename your step definition file to *.step.ts

Upvotes: 1

Related Questions