Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

const { assert } = require('chai'); const { doShortly } = require('../answers/01.js'); describe(doShortly, function() { // switch from 2 second default mocha timeout to 1

image text in transcribed

const { assert } = require('chai'); const { doShortly } = require('../answers/01.js');

describe("doShortly", function() {

// switch from 2 second default mocha timeout to 1 second. this.timeout(1000);

before(() => { console.log(`LHL Note: "Timeout of 2000ms exceeded..." is a generic message from Mocha if our delayed execution doesn't happen.`) console.log(` Mocha waits 2 seconds (by default) before giving up on the test. This error should go away once the callback is invoked.`); })

it("calls/invokes the provided callback", (done) => { doShortly(() => { assert.isOk(true, "expected callback to execute"); done(); }, 10); });

it("calls/invokes the provided callback with the provided data", (done) => { const data = 5;

doShortly((param) => { assert.strictEqual(param, data); done(); }, 10, data); });

it("defers the execution/invocation of the provided callback function by the given ms delay (800ms)", (done) => { const before = new Date(); doShortly(() => { const after = new Date(); assert.approximately(after - before, 800, 200); done(); }, 800); });

it("defers the execution/invocation of the provided callback function by the given ms delay (200ms)", (done) => { const before = new Date(); doShortly(() => { const after = new Date(); assert.approximately(after - before, 200, 120); done(); }, 200); });

it("returns undefined despite calling the callback", (done) => { const results = doShortly(() => { assert.isOk(true, "expected callback to execute"); done(); }, 10); assert.isUndefined(results); });

});

please can anyone solve this problem and this codes use in providing task 01

"use strict"; /* Question 01 Implement a function which can run a given function after a delay. Arguments: - callback: the function to execute after the delay - delay: number of milliseconds to wait - data: the one (and only) argument to pass to the callback */ = const doShortly = function(callback, delay, data) { // IMPLEMENT ME }; // Don't change below: module.exports = { do Shortly }; = 12:31 am V/

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions