I am having trouble with my jest-cucumber test not properly recognizing my step definitions

I recently started using the jest-cucumber library to execute my jest tests in BDD format.

However, when I try running a sample test, I encounter the following issue:

? 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

Here is where you can locate the files:

https://i.sstatic.net/evXtK.png

Outlined below are my BDD scenarios:

Feature: E2E Tests

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

This is how my Step definition code looks like:

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

Feeling a bit stuck on what my next move should be!

Answer №1

Be sure to change the extension of your step definition file to *.step.ts

Answer №2

It seems like he is suggesting the following:

Incorporate this into your Jest setup:

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

Refer to the jest-cucumber documentation for more information https://www.npmjs.com/package/jest-cucumber.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

When you utilize useSelector, the state may be returned as undefined even after it has been initialized

In the process of developing a project that mirrors Twitter(X), my approach involves implementing state management with REDUX and maintaining persistent login using redux-persist. I am storing the user's username and token in both the Redux store (for ...

Initializing various objects on the same interface type array in one line

Is there a way to inline initialize an array of the interface type IFooFace in TypeScript with different specific implementations, similar to how it can be done in C#? Or do I have to initialize my objects before the array and then pass them in? In C#, th ...

Nest JS - The client validation has not passed: The path field is mandatory

I'm seeking help here because I've hit a roadblock with an issue I've been facing for the past few hours. I'm working on building an API using Nest JS 8 and MongoDB, which I test using Postman. When I try to send a POST request (http:// ...

Enhance the array by updating objects within it using the spread operator

I'm looking to modify the name of the second object in a javascript/typescript array. Here's my array: let array = [{id:1,name:'One'}, {id:2, name:'Two'}, {id:3, name: 'Three'}] Is there a way to update the name of ...

Validation of emails in Angular through the utilization of reactive forms

Hello there, I'm new to Angular and looking for some assistance. Specifically, I am currently working on validating an email input using a reactive form with the keyup event. registerform:any; ngOnInit(): void { this.registerform = new F ...

Creating a function that can have either one or two arguments, with the types of the arguments determined by a specific string literal

I am looking to create a function called emitEvent(event, extra?), which will be restricted by a string literal enum of known strings such as POPUP_OPEN and POPUP_CLOSED. The function will accept a second argument that is a specifically defined dictionary ...

Seeking out a particular key within a JSON object and then finding a match based on the id within that key's array - how can it be

Recently, I've been exploring JavaScript and encountering challenges when trying to apply array methods on objects. For instance, I received a fetch response and my goal is to extract the 'entries' key and then utilize the native Array.find( ...

The browser appears to be interpreting the JavaScript file as HTML, resulting in the error message "Uncaught SyntaxError: Unexpected token '<'"

Referencing a similar unresolved question here: Browser seems to read react JS file as HTML, not JSX I am currently working on a project that is developed with Next.js, React, and Typescript. However, I am facing an issue while trying to integrate a Java ...

Exploring nested keys within JSON data using TypeScript

I am currently working with this object structure { "Monday": [ { "morning": [ { "start_time": "02:00", "end_time": "07:3 ...

When trying to convert a jest test to typescript, an error message may be encountered stating: "SyntaxError: Unable to

As I delved into the clear and concise jest documentation, I managed to successfully implement this test: const { spawnSync } = require('child_process'); const ls = spawnSync('ls', ['-lh', '/usr']); const unexistent ...

Determine if an object contains a specific key in Typescript and access the value associated with that

Here is a snippet of my code: let show = { createTag: false, updateFeature: false, createFeatureGroup: false, deleteFeature: false, deleteCycle: false, }; I am retrieving a value from the querystring that I want to compare against the ...

Is it possible to view the list of errors displayed by vscode when opening a JS file exclusively through the terminal?

Is there a default configuration file that vscode uses to display errors and warnings? I want to identify all issues in my JavaScript project. I don't have any jsconfig.json or tsconfig.json files, only using the //@ts-check directive in some files. ...

Issue encountered: Unable to locate module - Error: Unable to resolve '@angular/core'

After completing all the installations, I attempted to run the repository angular2-webpack-starter. However, when executing the commands npm start or webpack, I encountered the following errors: Error messages related to missing modules: ... (list of var ...

Unable to display information on mat table without receiving an error message

Hello everyone, I am a novice in Angular and I seem to be encountering an issue with displaying data on my mat table. Surprisingly, no errors are being shown. While I can see the column names, the actual data is not visible. Can someone help me figure ou ...

When processing JSON data, Typescript is unable to interpret a map<string,string> structure

I am currently working with Angular5 within a spring boot application and I am attempting to retrieve a Map object in JSON format. Spring : //sample method return ResponseEntity.ok((new Gson()).toJson(/*My map object*/)); Angular5 : sql_list = new Map& ...

Tips for accessing data from a local JSON file in your React JS + Typescript application

I'm currently attempting to read a local JSON file within a ReactJS + Typescript office add-in app. To achieve this, I created a typings.d.ts file in the src directory with the following content. declare module "*.json" { const value: any; ex ...

Is there a way to retrieve the value of bindings in the component controller using Angular 1.5 and Typescript?

In my quest to develop a versatile left-hand menu component that can dynamically display different menu structures based on input strings, I stumbled upon an interesting challenge. By binding a string to the <left-hand-menu-component> element like so ...

In TypeScript, the <promise void> statement takes on a special significance

Currently, I am diving into the world of typescript but there are a few concepts that still elude me. Some of these include: 1) My confusion lies within this snippet of code: Object = Object.assign export const htmlElementsMap: Object = Object.assign( ...

Angular is having trouble locating the module for my custom library

Trying to implement SSR in my angular application, but encountering an error when running npm run build:ssr. I've created my own library named @asfc/shared, which is bundled in the dist folder. ERROR in projects/asfc-web/src/environments/environment. ...

Combining data from various API calls into one cohesive array using RXJS

My RXJS Pipeline is structured as follows: const logs: number[] = [1, 2, 3, 4]; const url = 'http://some-url-here.com'; const pipeline = from(logs).pipe( switchMap(logId => this.callEndpoint(url, logId).pipe(map(response => response. ...