Is it possible to apply async/await within a describe block?

I have been struggling to run the following complete end-to-end test for my project. I have a collection of pages, each consisting of a page title and a list of steps required. However, in order to retrieve these pages, an asynchronous call is necessary. Consequently, the 'it' method is not being executed as expected.

I am looking for a way to loop through the 'it' method for all the pages in my array.

describe('Test Suite', () => {
    let pages: Page[]; //Page = { Name: string, testSteps: string[] } 
    beforeAll(async () => {
        pages = await service.GetPages();
    });
    pages.forEach((page) => {
        it("Test Cases", () => {
            return executePageTests(page);
        });
    });
});

Answer №1

Jasmine does not have direct support for Promises, but it does offer asynchronous callbacks using a done function for certain functions like beforeEach, it, and afterEach, excluding describe. This restriction ensures fast test discovery as making asynchronous calls for test case generation is not allowed.

Your best option is to have a single test that runs all test cases.

   it("Test all cases", done => { 
     service.GetPages().then(pages => { 
        pages.forEach(executePageTest);
        done();
     });
   })

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

typescript leaflet loading tutorial

I'm attempting to replicate the basic example of loading a map with Leaflet in TypeScript, following the guidance on the Leaflet website. I am not utilizing any frameworks like Angular or React. I have installed Leaflet and types through npm. To adher ...

The standard category of class method parameter nature

I'm encountering difficulties when attempting to correctly define a method within a class. To begin with, here is the initial class structure: export class Plugin { configure(config: AppConfig) {} beforeLaunch(config: AppConfig) {} afterSe ...

Failure of Gulp Dest() to Generate File Output

Struggling to make gulp.dest output correctly. I'm aiming to output to the root of an ASP.NET Core project that I'm repurposing for TypeScript development. Any guidance on how to achieve this would be greatly appreciated. Below is the current con ...

Issue with Vue 3 component not updating following vue-router invocation

I am currently working on developing a todo app using ionic-vue with vue 3. In my Lists.vue component, I have set up an overview where users can click on different lists to load tasks specific to each list. However, I am facing an issue where the same data ...

What is the syntax for adjusting background-position with ngStyle in Angular 4?

It's finally Friday! I'm a bit confused about how to properly set the background-position-x property in an [ngStyle] directive in Angular 4 with Ionic 3. Can someone guide me on the correct way to implement background-position-x? I expect the ou ...

What is the reason that control flow analysis does not support the never type?

Here is the scenario I'm dealing with (utilizing strictNullChecks): function neverReturns(): never { throw new Error(); } const maybeString: string | null = Math.random() > 0.5 ? "hi" : null; if (!maybeString) { neverReturns(); // th ...

Explain the const/type pattern in TypeScript

const INCREMENT_ENTHUSIASM_LEVEL = 'INCREMENT_ENTHUSIASM_LEVEL'; type INCREMENT_ENTHUSIASM_LEVEL = typeof INCREMENT_ENTHUSIASM_LEVEL; const DECREMENT_ENTHUSIASM_LEVEL = 'DECREMENT_ENTHUSIASM_LEVEL'; type DECREMENT_ENTHUSIASM_LEVEL = t ...

``Are you experiencing trouble with form fields not being marked as dirty when submitting? This issue can be solved with React-H

Hey there, team! Our usual practice is to validate the input when a user touches it and display an error message. However, when the user clicks submit, all fields should be marked as dirty and any error messages should be visible. Unfortunately, this isn&a ...

Initiating preparation during NPM Installation

During the installation of a TypeScript module from Git, I noticed that the package.json file contains a prepare script in its scripts section. Strangely, it seems that the prepare script is not being run when using npm install <git repository#version&g ...

In TypeScript, leveraging the spread operator to determine the largest value in an array containing nullable numbers

Having an array of nullable numbers presented in the following way: let myArray : Array<number | null> = [1,2,null,4,null,5]; let maximumOfMyArray = Math.max(...myArray); // Type null is not assignable to type number I am content with JavaScript tre ...

Ways to convert all keys to uppercase in an array of objects?

Is there a way to capitalize the first letter of every key in an array of objects? I attempted to achieve this with the code below, but it's not working as expected. Any suggestions or corrections are appreciated. #current code function capitalizeO ...

Trouble with Excel Office Script setInterval functionality

Trying to automatically recalculate an Excel worksheet every second using Office Script. Unfortunately, my initial approach did not succeed. function sendUpdate(sheet: ExcelScript.Worksheet) { console.log('hi'); sheet.calculate(true); } func ...

discovering unique values within a collection of numerical data using Typescript

Just starting out with TypeScript and wondering how to identify unique numbers from an array of numbers. Can I apply the standard filter function used in JavaScript, or is there a specific approach for TypeScript? Thanks for any help! ...

Assign updated values to a list based on changed fields in the map

In order to track the modified fields and display them to the user, I need to identify which key corresponds to the changed field and create a new key-value pair for user visibility. log: [ 0: {type: "Changed", fields_changed: Array(2), date_modificat ...

What is the best way to export a default object containing imported types in TypeScript?

I am currently working on creating ambient type definitions for a JavaScript utility package (similar to Lodash). I want users to be able to import modules in the following ways: // For TypeScript or Babel import myutils from 'myutils' // myuti ...

Setting a value in the selectpicker of rsuitejs involves assigning a specific value to the

const _DATA = [{ code: 'code1', name: 'Jagger' },{ code: 'code2', name: 'Tigger' },{ code: 'code3', name: 'Lion' }] <SelectPicker data={_DATA.map(x => {return {label: x.n ...

Error TS2403: All variable declarations following the initial declaration must be of the same type in a React project

While developing my application using Reactjs, I encountered an error upon running it. The error message states: Subsequent variable declarations must have the same type. Variable 'WebGL2RenderingContext' must be of type '{ new (): WebGL2 ...

Utilizing React with Typescript: A guide to working with Context

I have a super easy app snippet like import React, { createContext } from 'react'; import { render } from 'react-dom'; import './style.css'; interface IAppContext { name: string; age: number; country: string; } const A ...

Encountering NG0204 error while utilizing the ActivatedRoute within an Angular application

Encountering an issue with ActivatedRoute while running the ng serve command on my Angular project: Error: NG0204: Can't resolve all parameters for ActivatedRoute: (?, ?, ?, ?, ?, ?, ?, ?). at getUndecoratedInjectableFactory (core.mjs:9296:15) ...

The importation of TypeScript source modules is not compiled accurately in the distribution folder

Currently, I am working on a REST API in TypeScript with the following structure: ├── dist │ ├── index.js │ ├── library.js ├── src │ ├── index.ts │ ├── library.ts ├── node_modules ├── package. ...