Endless jasmine timeout

This question is a continuation of a discussion on the Remove timeout for single jasmine spec GitHub issue.

Query:

Can a single test be configured to never time out?

The Issue:

While it's possible to set a global timeout value using DEFAULT_TIMEOUT_INTERVAL, or set timeouts for each describe block with beforeEach/afterEach, or even on an individual it() block like below:

it('Has a custom timeout', function() {
  expect(true).toBeTruthy();
}, timeout value in milliseconds)

I'm specifically looking to prevent a single test from timing out indefinitely. I tried following the suggestion from the GitHub issue by using Infinity:

it('Has a custom timeout', function() {
  expect(true).toBeTruthy();
}, Infinity)

However, I encountered this error immediately after the test entered the it() block:

Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL

It seems that using Infinity as a timeout value may not be allowed, or I might be missing something.


For now, I can use a large hardcoded number as a workaround, but I'd prefer to find a better solution.

Answer №1

Jasmine utilizes the setTimeout function to wait for test specifications to complete within a specified time frame.

In response to the question found on Why does setTimeout() "break" for large millisecond delay values?:

The issue lies in setTimeout using a 32-bit integer to store the delay time

...

When timeout values exceed what can be stored in a signed 32-bit integer, it may cause overflow in browsers like Firefox, Safari, and Chrome, leading to an immediate scheduling of the timeout event. In such cases, it is more practical not to set these timeouts given that expecting a browser window to stay open for 24.8 days is unreasonable.

An overflow occurs once Infinity surpasses any other number.

The maximum safe integer in this scenario is 231-1 = 2147483647. This finite value ensures that the test will not run infinitely, despite the threshold of 24.8 days being already extensive.

To handle this effectively, you can define a constant to hold this value:

jasmine.DEFAULT_TIMEOUT_INTERVAL = 2000;

var MAX_SAFE_TIMEOUT = Math.pow(2, 31) - 1;

describe('suite', function () {

  it('should work within a defined period', function (done) {

    setTimeout(function () {
      expect(true).toBe(true);
      done();
    }, 3000)

  }, MAX_SAFE_TIMEOUT);

});

For a demonstration, refer to this working sample

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

Display user profile pictures from Vue.js in the Laravel public directory

I have been working on implementing a commenting system and recently incorporated vue.js into my laravel project. One of the features I want to include in my comment area is displaying user profile images from the laravel public folder. However, I am u ...

What is the best way to implement a function on every item within a specific class?

I'm new to coding and I have a website that showcases job listings. I want to create a function that dynamically changes the logo of a company based on the first 50 characters of the company name mentioned. The current function only works for the firs ...

Modifying the class of an HTML element using JavaScript

Is it possible to dynamically change the class of an HTML element based on a user's selection with a radio button? I am facing an issue where I receive the following error message: "Error: missing ) after argument list Source File: website Line: 1, C ...

Guide to linking a specific event with JQuery event handlers

I have a Javascript function named Howto that is triggered by a button press: function howto(){ $('#elementtoupdate').ajaxSend(function() { //Code to run }); $('#elementtoupdate').ajaxComplete(function() { //Co ...

Can you explain the distinction between $(document) and $('*') and how can we determine which library $ is referring to?

My interpretation is this: $(document) will contain the entire DOM of the current page just like document, while $('*') also selects the entire DOM. What sets them apart, aren't they essentially the same? Will assigning $ from different lib ...

Utilizing Jquery to enhance table filtering functionality

I created a table listing various places, along with buttons to filter the list. The first filter is based on location (north, east, central, south, west) determined by postcode. The other filter is for "impress" which only displays places with a rating of ...

Issue encountered when attempting to retrieve elements within an HTA's IFrame

We are currently working on automating an Intranet site using HTA and JavaScript. To bypass the browser security settings, we have implemented an Iframe within the HTA itself instead of opening the site in a browser. Despite being able to successfully logi ...

Why does the shadow in Three.js only appear in a limited region?

I brought in a model and noticed that the shadow is only visible in a small area (highlighted in green in the image). How can I make all objects display their shadows? https://i.sstatic.net/hmzp2.png Below is my code snippet. light = new THREE.Direction ...

Using JavaScript, divide a string containing elements of unknown length that may be adjacent based on their type

If I have a string representing an SVG path like: "M72 0v754h405v-86h-311v-211h302v-86h-302v-285h311v-86h-405z" My goal is to transform it into an array where each element consists of either a letter or a positive/negative number. For example: [ ...

"Utilizing the splice method to insert an element at specified indexes within an

const list = [] const obj = { name: '', mobile: '' } _.forEach(errors, (value, key) => { // eslint-disable-next-line no-debugger // debugger const field = key. ...

Numerous Radio Buttons

I am currently working on creating a quiz similar to those found on Buzzfeed and Zimbio. I apologize if this question has been asked before, but despite my efforts in searching, I have not been able to find the answer I am looking for. In this quiz, partic ...

Submitting forms using AJAX in Django

I am getting a 'Not Ajax' response every time I try to submit my form. There must be something small that I'm overlooking... class VideoLikeView(View): def post(self, request): if request.is_ajax(): message = 'Aj ...

Importing JSON Data into an HTML File

I need to load a JSON file containing HTML content into my main HTML file upon clicking a button. ABC.json includes: <li><img src="images/picture6.jpg" /></li> <li><img src="images/picture5.jpg" /></li> <li><i ...

An error has occurred in the Node.js module export due to an unexpected token

While working on my controller, I initially wrote it like this: module.exports.create_payment = function(){ console.log('create_payment') } However, I encountered an issue with this approach. If I have 10 methods in one controller, I would ...

Retrieve information from an array of objects by utilizing a separate array

There are two separate arrays provided below: ages = [20,40,60]; doctors = [{ "name": "Moruu", "age": 18, "sex": "Male", "region": "Africa" }, { "name": "Khol ...

Create a CSV document using information from a JSON dataset

My main goal is to create a CSV file from the JSON object retrieved through an Ajax request, The JSON data I receive represents all the entries from a form : https://i.sstatic.net/4fwh2.png I already have a working solution for extracting one field valu ...

During the rendering process, the property "instance" was attempted to be accessed but is not defined

I am having trouble creating a Contact Us page using v-model. My code keeps throwing these errors: Property "inputted_name" was accessed during render but is not defined on instance Property "inputted_email" was accessed during render but is not defined o ...

Increase the timestamp in Typescript by one hour

Is there a way to extend a timestamp by 1 hour? For instance, 1574620200000 (Including Microseconds) This is my date in timestamp format. How can I add a value to the timestamp to increase the time by an additional hour? ...

Guidelines for populating data with an array

I have the following array: const dataArr = [[15, 14, 5], [16, 10, 2], [17, 6, 13], [18, 4, 8], [19, 7, 4]]; Now, I am populating another array using the above data as shown below: for (let i=0; i<dataArr.length; i++){ newData.push(dataArr[i]); ...

Transferring hyperlink text to a different page using Express JS

I'm currently dealing with a coding issue where I need to pass a link text within a hyperlink to another page. The web application is built using Express. On one of the pages, there's a dropdown list containing this hyperlink: <a class=" ...