Tuesday 26 November 2019

Testing async function with mocha

My code looks like this ::var expect = require('chai').expect;var should = require('chai').should;var _ = require("lodash");function asyncTask(){setTimeout(function(){console.log("After 2 seconds");},2000);}describe("Test", function(){it('Test Async', function(done){asyncTask();done();});})The output of the following code is :::Test✓ Test Async​​1 passing (6ms)​After 2 secondsAs you can see after 2 seconds is being printed after test has been passed but if I need to do some validation from the returned result from asyncTask how do I do that? Test should be passed after async call is complete. Is there any way to acheive this?

Submitted November 26, 2019 at 02:32PM by GhostFoxGod

No comments:

Post a Comment