To make sure that async tests and hooks are properly handled, remember to call "done()" after completion. If you are returning a Promise, make sure that it resolves properly for puppeteer and

I am currently testing my component using mocha and Google Puppeteer. In my unit test file, I have set up the Puppeteer browser to launch before the tests and close after the tests in the respective functions. However, when running the test file, I encountered the following error message within the "Before All" hook: "Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure 'done()' is called; if returning a Promise, ensure it resolves."

const puppeteer = require('puppeteer');
const { expect } = require('chai');
const _ = require('lodash');

/* Create global variables using lodash function */
const globalVariables = _.pick(global, ['browser', 'expect']);

/* Configurable options or object for Puppeteer */
const opts = {
    headless: false,
    slowMo: 100,
    timeout: 0,
    args: ['--start-maximized', '--window-size=1920,1040'] 
}

/* Set up Puppeteer before executing the code */
before(async () => {
  global.expect = expect;
  global.browser = await puppeteer.launch(opts);
});

/* Close the browser after testing */
after(() => {
  browser.close();
  global.browser = globalVariables.browser;
  global.expect = globalVariables.expect;
});

Answer №1

To customize the timeout for your unit test cases, navigate to the root directory where your test files are stored and create a file named mocha.opts. Inside this file, add the line --timeout 50000 to set Mocha to timeout after 50000 milliseconds.

The reason you are encountering errors is because the default timeout is currently being enforced, preventing the completion of your test actions.

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

Extracting address from a string containing HTML line breaks and apostrophes using JavaScript

I need help with parsing an address that is in a string format like the following: "1234 Something Street<br>Chicago, IL 34571<br>" I am struggling to extract and assign it to separate variables: var street = ...; var city = ...; var state = ...

Semantic UI form validation is initiated by clicking any button

Within my Semantic UI form (<div class="ui form">), it seems that every button is triggering the form validation, even if it's not a submit button. I have two different types of buttons below: <button class="ui blue right labeled icon prima ...

The issue of uploading files using Ajax in CodeIgniter and Jquery is causing problems

I am attempting to implement a file upload using Ajax in CodeIgniter, but it seems like my Jquery code is not properly retrieving the data from the form even though the file appears to be included in the POST message. Below is my controller: public funct ...

Enhanced JavaScript Regex for date and time matching with specific keywords, focusing on identifying days with missing first digit

I have a specific regular expression that I am using: https://regex101.com/r/fBq3Es/1 (audiência|sessão virtual)(?:.(?!audiência|sessão virtual|até))*([1-2][0-9]|3[0-1]|0?[1-9])\s*de\s*([^\s]+)\s*de\s*((19|20)?\d\d) ...

Displaying various Ajax html responses

The function $('.my-button').click(function(e) is designed to display the output of the MySQL query in display.php, presented in HTML format. While it functions correctly, since each button is looped for every post, the script only works for the ...

Executing a serverless function in Next.js using getStaticPaths: A step-by-step guide

In my current project, I am utilizing Next.js and the Vercel deployment workflow. To set up page generation at build time, I have been following a guide that demonstrates how to generate pages based on an external API's response. // At build time, t ...

What is the best way to append data to the end of an object using ReactJS Hooks?

Looking to set up a checkbox page in ReactJS where data is filtered by checkboxes from different categories using ReactJS hooks. Currently, I am storing the selected checkboxes as an object: { color: 'orange', shape: 'square' } ...

Methods for decoding a JSON object and iterating through its contents

After learning how to encode an object on the server side from this post, I am now interested in decoding it on the client side. Following is what I do on the client side: $.ajax({ type: "GET", url: "/cgi-bin/ajax_sort.pl", contentType: "appl ...

What is the best way to isolate the elements from the specified dictionary that contain valid data?

I need to extract only the data for Flipkart from this array and create a new array containing just that information. json = [ { "amazon": [] }, { "flipkart": { "product_store": "Flipkart", ...

I keep encountering the following error message: " ERROR Error Code: 200 Message: Http failure during parsing for http://localhost:3000/login"

My Angular Login component is responsible for passing form data to the OnSubmit method. The goal is to send form data from the front-end application and authenticate users based on matching usernames and passwords in a MySQL database. ***This login form i ...

Encountered an Error with My Protractor Script - Object Expected

Currently, I am in the process of learning automation testing for an AngularJS application. However, I have encountered an "object expected" error on line 4, which is pointing to the first line of my script. describe("Homepage", function() { it("Navig ...

The responseText array is encountering parsing issues

Utilizing ajax, I am retrieving a json_encoded array from my PHP parser. The responseText returned is ["4.wav","2.wav","3.wav","6.mp3","1.mp3","5.wav"] If I place this into an array like so: var myArray = ["4.wav","2.wav","3.wav","6.mp3","1.mp3","5.wav" ...

How to trigger a JavaScript refresh during debugging in Visual Studio 2012

Currently, I am grappling with debugging scripts in my ASP.NET project using VS2012. Whenever I initiate the project, errors start to appear from a third-party library. The issue I am facing is that even after making changes to the scripts, they are not r ...

Troubleshooting a JavaScript error: Script.js throwing 'Uncaught TypeError' at line 5

While working on a small project, I encountered a JavaScript error that reads: script.js:5 Uncaught TypeError: Cannot set properties of null (setting 'onkeyup') at script.js:5:18 Below is the HTML & JavaScript code snippet that triggered thi ...

Homepage divided in two sections akin to the Tumblr landing page

Have you ever visited www.tumblr.com and noticed the '30 reasons...' link on the registration page that slides up and reveals a second page? I've been trying to figure out how they achieve this cool effect. Most tutorials show how to scroll ...

Send JSON information to Bottle's endpoint

As a beginner with Bottle and somewhat with Python, I am working on creating an app that triggers an AJAX request to POST a JSON to the server and store it using SQLite whenever a button is clicked. Currently, I am struggling to understand how to effectiv ...

Best practices for stubbing an element in order to effectively unit test a LitElement component

Trying to perform unit tests on LitElement components has been quite a challenge for me. I found myself stuck when attempting to isolate components, particularly in figuring out how to stub elements effectively. The Polymer project provides some informatio ...

Combine the PHP table with the Javascript table

I am facing a challenge where I have a table in PHP and another table in Javascript. My goal is to combine the elements of the PHP table with the elements of the Javascript table. I attempted to achieve this using the push method: <?php $tabPHP=[&apos ...

Transition smoothly from the first texture to a solid color, and then seamlessly switch to the second texture using a GLSL Shader

I am working on a GLSL fragment shader that aims to achieve the following sequential effects: Transition from texture 1 to a specific color Transition from the color to texture 2 Here's my initial attempt: // Uniforms uniform sampler2D tex1; uniform ...

The post request fails to send certain variables

I'm experiencing an issue with a form that has rows structured like this: <div class="row unit" onmouseover="this.style.background = '#eeeeee';" onmouseout="this.style.background = 'white';" onclick="if(event.srcElement.nodeNam ...