Leveraging cy.tick() in combination with rxjs auditTime

An end-to-end test has been developed for a feature that utilizes ngrx state management. This particular feature gathers user inputs over a span of 60 seconds using the auditTime() operator and then sends them to an API endpoint.

To speed up testing, instead of waiting for the full 60 seconds each time, there was an attempt to use the cy.tick(58000) function to fast forward time. However, it seems that this method doesn't actually skip time as expected.

it('should send a http post request after 60 seconds', () => {
        cy.intercept('POST', '**/my-page').as('my-post'); // intercept the post
        cy.clock(); // instantiate clock object
        cy.visit('/home'); // visit page

        // some inputs here
        cy.tick(58000); // skip 58 seconds

        // this wait command times out
        cy.wait('@my-post', { timeout: 15000 }).then((interception: any) => {
            const statusCode = interception.response.statusCode;
            expect(statusCode).equal(200);
       });
});

The observable that uses the auditTime operator is generated within an ngrx effect:

postObservable$ = createEffect(() =>
    this.store.select(FromData.selectData).pipe(
        auditTime(60_000), // important part
        filter((data) => data.length > 0),
        map((result) => [
            ...result.map((dataElement) =>
                toDataDTO({
                    dataId: dataElement.postId,
                    createdAt: dataElement.createdAt,
                })
            ),
        ]),
    ...
});

Every time, the test reaches a timeout after 15 seconds. It functions properly if the auditTime() duration is reduced to one second or shorter.

Is there a way to ensure that Cypress ticks can effectively work with rxjs operators like auditTime()?

Answer №1

To mimic the time parameter, one approach is to create a mock.

const timeParam = window.Cypress ? 300 : 60_000;

postObservable$ = createEffect(() =>
    this.store.select(FromData.selectData).pipe(

        auditTime(timeParam), 

        filter((data) => data.length > 0),
        map((result) => [
            ...result.map((dataElement) =>
                toDataDTO({
                    dataId: dataElement.postId,
                    createdAt: dataElement.createdAt,
                })
            ),
        ]),
    ...
})

This adjustment may potentially disrupt the app's logic, such as causing race conditions with other Rx feeds.


As clock() manages Date, setTimeout(), and setInterval(), I explored whether these impact the timing of auditTime(). The existence of a TimestampProvider utilizing Date.now() was noted, but effectively mocking it remains unclear.

Alternatively, the TestScheduler might offer a way to hasten the interval, yet its utilization in an end-to-end test appears challenging.

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 is unable to interpret an anticipated overloaded function signature

I'm currently facing challenges with TypeScript overload resolution. When using the googleapis library with TypeScript to fetch all tag manager accounts records, the list function requires pagination if the response body contains a nextPageToken. I a ...

Solving the issue of loading Ember Initializers during the transition to TypeScript

While following the ember quick start tutorial, I attempted to switch from Javascript to Typescript. Converting the .js files to .ts files resulted in an error with the ember-load-initializers import. The application is unable to run until this issue is re ...

Retrieve the runtime configuration object or file using Jest

Is there a way to access the Jest runtime config object or file path? I wanted to utilize runtime config properties in my custom matchers. // ./jest.config.js const path = require("path"); module.exports = { prop1: "foo", prop2: "bar" }; // my-custo ...

Prefer using 'as Movie[]' over '<Movie[]>' in @typescript-eslint/consistent-type-assertions rule suggestion

I am currently working with a Vuex store: type Movie = { title: string; id: number; } export default new Vuex.Store({ state: { searchList: <Movie[]>[], }, Upon compiling my code, an error is generated: The error message suggests to re ...

Explore Angular's ability to transform a nested observable object into a different object

My task involves mapping a field from a sub object in the response JSON to the parent object The response I receive looks like this: { "id": 1, "name": "file-1", "survey": { "identifier": 1, "displayedValue": survey-1 } } I am attempting ...

How to dynamically load a component in Angular 7 with the click of a button

I am looking to implement a feature where clicking on a row in my table will load a specific component. In order to test this functionality, I have created a simple alert that pops up when a row is clicked displaying the message THIS ROW HAS CLICKED. This ...

Error display in Elastic Apm Rum Angular implementation

Having some issues with incorporating the @elastic/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="f5948598d8878098d8949b9280999487b5c7dbc4dbc4">[email protected]</a> package into my project. Angular is throwing console ...

The attribute 'X' is not present in the specified type 'IntrinsicAttributes & InferPropsInner'

I've been restructuring my code from a .js file to a .tsx file, as seen below: import React, { useEffect, useState } from 'react' import PropTypes from 'prop-types' import { checkMobile } from '../../utils/common' import ...

Can you explain how to adjust the font size for table data in OfficeGen?

I am currently utilizing officeGen library to automatically create word documents. generateDocumentService.js: var generateReportFromTableData = function (tableData) { console.log('tableData: ', tableData); var docx = officegen({ type: &a ...

`Incorporating ordered indices within two ngFor loops?`

Below is a demo code where I am explaining my goal through comments: product.component.html <div *ngFor="let item of items1"> <div *ngFor="let item of items2"> <input type="text" value="{{data[getNumber()]}}"> //I aim to fe ...

Nativescript encountered an issue while attempting to generate the application. The module failed to load: app/main.js

I'm currently experimenting with the sample-Groceries application, and after installing NativeScript and angular 2 on two different machines, I encountered the same error message when trying to execute: tns run android --emulator While IOS operations ...

Tips for effectively utilizing the Ngrx navigation function

While exploring NgRx, I stumbled upon navigation. According to the documentation, it seems like this effect should trigger when the component loads. However, I'm facing an issue where this effect is not getting triggered. Other effects that I've ...

In order to access the localStorage from a different component, a page refresh is required as it is

UPDATE: Just to clarify, this question is NOT duplicate of how to retrieve the value from localstorage. My scenario is unique and the issue lies with Angular itself rather than localStorage. I am currently developing an Angular7 application. In one of my ...

Exploring the Capabilities of TypeScript 1.8 in Visual Studio 2017

Recently, I've encountered an issue with my Visual Studio project that was created using TypeScript 1.8 in Visual Studio 2015. Upon upgrading to Visual Studio 2017 and attempting to open the project in the new IDE, I noticed that the TypeScript versio ...

Troubleshooting Node.js TypeScript breakpoints in Visual Studio Code

I've attempted multiple solutions, but none seem to be working for me. Although the code is running, I'm having trouble setting breakpoints and debugging it. Can you offer any assistance? Below is the configuration script I've tried in VSCo ...

Attempt to reprocess the observable queue three times, starting from the point of failure

I have an array of observables that I need to subscribe to one at a time, waiting for each to finish before moving on to the next. If any of the observables fail, I want to retry them a few times before moving on. I am struggling to find an efficient way t ...

How to verify the existence of an object property in typescript

I am dealing with a queryParams object that I need to use to query the database based on its properties. However, I am unable to determine which parameters it contains. I attempted to utilize find(queryParameters: object = { limit: 50 }){ if (queryParamete ...

What is the specific category of Mongoose.startSession in the realm of Typescript?

In my Express/Typescript project with mongoose, I implemented a loader as follows: import mongoose from 'mongoose'; import { Db } from 'mongodb'; import config from '../config'; export default async (): Pr ...

Is there a way to verify whether a key within an Interface corresponds to a class that is a subclass of a specific Parent

Is there a method in typescript to ensure that a property in an interface must be of type "child subclass C, which extends class P"? example.ts import { P } from '/path/to/types' class C extends P { ... } types.ts // `C` cannot be accessed ...

Injecting dependencies into an abstract class in typescript using Angular 2

So I have an abstract class that doesn't have a constructor, and my goal is to inject another class into it. Here's the abstract class: import { ErrorHandler } from '../../shared/services/errorHandler.service'; import { Inject } from ...