Is it a problem with Cucumber Js callbacks or a feature issue?

I would like to create a scenario similar to this:

Scenario: initialize new Singleton
  When an unmatched identity is received for the first time
  Then create a new tin record
   And establish a new bronze record
   And generate a new gold record

This scenario should be connected to steps like these:

defineSupportCode(function ({ Before, Given, Then, When }) {

  var expect = require('chai').expect;
  var chanceGenerator = require('./helpers/chanceGenerator')
  var request = require('./helpers/requestGenerator')

  let identMap;

  // reset identMap before each scenario 
  Before(function () {
    identMap = [];
  });

// more code...

The challenge I am facing is that I am unable to perform any actions within the Then callback. This is where I want to verify if the response contains the correct data.

Here are some relevant excerpts from the helper files:

// functions for handling POST and GET requests for identity records
var pubPostIdentity = function (ident, callback) {
  // code here...
}

var pubGetIdentity = function (ident, callback) {
  // code here...
}

We are considering rewriting the feature with a different step definition structure to avoid the callback issue. For example:

Scenario: initialize new Singleton
    When receiving an unmatchable 'TIN_RECORD'
    Then ensure successful creation of the Identity Record
    When retrieving the Identity Record for 'tin'
    Then create a new 'tin'
    // more steps...

While this revision may resolve the callback problem, it compromises the readability and clarity of the feature. It may not be easily understood by non-technical stakeholders.

So my question is, is the initial summary feature poorly written? Am I expecting too much from the step definitions, or is there a mistake in my JavaScript implementation?

Answer №1

First of all, I must point out that your revised feature is incorrect. It's important to follow the order of Given, When, Then without going back. Reversing the sequence from Then to When is not the right approach.

The Given step establishes preconditions, the When step executes the actual test, and the Then step verifies assertions. Each scenario should represent a single test with minimal When clauses. If needed, Scenario Outlines can be used to combine similar tests.

In this situation, it is advisable to go back to basics and see if starting over helps solve the issue. Progress gradually to reach a working solution.

It appears likely that an unhandled exception is causing the problem. Consider refactoring the code to use promises, which can provide better error handling by rejecting on errors and improving error reporting.

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

Experiencing a hiccup while attempting to query the Twitter API using Node.js

I am a beginner exploring the world of node.js, but I keep encountering a perplexing "write after end" error. Despite searching for solutions online, none seem to address my specific issue. My current project involves querying the Twitter API. req.on(&apo ...

Can you explain the distinction between $and and $all in this specific scenario?

These two lines of code may seem similar, but is there a crucial difference between them? I understand the importance of documentation, but in this specific scenario, what sets them apart? Thank you for your insights! db.someData.find({$and: [{genre: {$eq ...

What is the best way to determine the property type dynamically in TypeScript based on the value of another property?

I have been working with Polymorphic relationships and currently have the following TypeScript interface defined: interface SubjectA {} interface SubjectB {} interface SubjectC {} enum SubjectType { SubjectA = 'Subject A', SubjectB = 'S ...

Using AngularJS in combination with a Flask backend to visualize the data being sent from the backend

I am currently developing a Single Page Application using Angular with a Python/Flask backend that connects to MongoDB. The challenge I'm facing is that, although I can retrieve data from the backend using a $http get request in Angular as an object ...

Implementing the use of a partial view in ASP.NET MVC with the help of JavaScript

I am faced with a challenge of displaying 15 different partial views based on the user's selection from a menu tab. Essentially, I have these 15 menu tabs on one side of the page, and when a user clicks on a tab, the content related to that tab should ...

Utilizing Material UI's TextField components for validating React forms

I've spent the past hour researching this topic and unfortunately, there isn't much information available on the internet. My goal is to validate input fields to ensure that all fields are filled out; otherwise, an error will be displayed. The le ...

Trouble accessing Silverlight site due to incomplete loading

There is a site known as that consists of a Silverlight application. Strangely, this site loads on all other computers except mine. I keep encountering the following error: An Error occurred in the Silverlight Application: String was not recognized as a ...

Automating the selection of a drop down based on a condition in Angular 2: A step-by-step guide

I'm facing an issue with a drop-down menu where no default value is selected. On my homepage, I need to automatically select an option based on query parameters. I've attempted various methods but none have been successful. Below is the code snip ...

Exploring the chosen choice in the Material Design Lite select box

Consider the following scenario. If I want to extract the name of the country chosen using JavaScript, how can this be achieved? <div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label getmdl-select getmdl-select__fullwidth"> ...

Include quotation marks around a string in C# to convert it into JSON format

I am utilizing a service that operates with JSON format. However, the JSON data I am receiving does not include double quotes around keys and values. Here is an example of the data I have: [{name:{buyerfirstname:Randy, buyermiddlename:null, buyerlastnam ...

How can you match the width of a series of elements to the width of an image directly preceding the div?

Looking to ensure that a series of captions have the same width as the images preceding them. This is the HTML code: <div class="theparent"> <img src="pic.jpg"/> <div class="caption"> hello </div> <div> <div ...

The Angular template driven forms are flagging as invalid despite the regExp being a match

My input looks like this: <div class="form-group"> <label for="power">Hero Power</label> <input [(ngModel)]="model.powerNumber" name="powerNumber" type="text" class="form-control" pattern="^[0-9]+$"id= ...

The file reading code in my Node.js application suddenly stopped working

I have a basic web application that I am currently developing using Node.js and Express. This is a breakdown of my package structure: https://i.stack.imgur.com/D7hJx.png The entries in my questions.json file are outlined below: [ { "question": "Wh ...

Using JavaScript to Apply CSS Styles in JSF?

Is it possible to dynamically apply a CSS style to a JSF component or div using Javascript? I have been searching without any success. Below is some pseudo code: <div style="myJSStyleFunction("#{myBean.value}")"> stuff </div> The function wo ...

Is there a way to detect the completion of the fadeout animation before calling a function?

I am trying to create a toast message using jQuery. When the "show" class is appended to the div, I want the toast message to fade in and then fade out after a few seconds. Once the fade-out animation is complete, I need to remove the "show" class. This ...

Implementing Jquery to attach a click event immediately after adding a new row to the table, all

I have an issue where I am adding a new row to my table. Within this row, there is a button that should be clickable and trigger an event. I have come across various solutions, but they all involve using the following code: .on('click', 'bu ...

Problem with object positioning in Three.js when applying rotation matrix

I am attempting to rotate an object named "moon" (which is represented as a sphere) using a matrix instead of the moon.rotation.y property. Here is the code I am using: moon.applyMatrix(new THREE.Matrix4().makeRotationY(Math.PI/100)); The rotation of the ...

Event listener is failing to execute the functions

Even though the inline onmouseover="verdadero()" function is properly set up Upon further inspection, it appears that while the event listener is added to the box element, the function is not being triggered when hovering over it, and console.lo ...

Show the current phone number with the default flag instead of choosing the appropriate one using the initial country flag in intl-tel-input

Utilizing intl-tel-input to store a user's full international number in the database has been successful. However, when attempting to display the phone number, it correctly removes the country code but does not select the appropriate country flag; ins ...

What is the best way to structure this React state container for modularity?

At my workplace, we have developed a state container hook for our React application and related packages. Before discussing what I'd like to achieve with this hook, let me provide some background information. Here is the functional code that's co ...