Mocha, nodejs promise test can't finish because lack of done

Mocha, nodejs promise test can't finish because lack of done

By : samai
Date : November 22 2020, 03:01 PM
seems to work fine Mocha supports testing promises without using done as long as you return the promise.
code :
const expect = chai.expect

it('should error', function(){
  return $configurations
    .updateConfiguration(configurations_driver.NOT_VALID_MODEL) //invalid model
    .then(()=> { throw new Error("Expected INVALID_MODEL error but got OK")})
    .catch(error => {

it('should error', function(){
  return $configurations
it('should error', async function(){
  try {
    await $configurations.updateConfiguration(configurations_driver.NOT_VALID_MODEL)
    throw new Error("Expected INVALID_MODEL error but got OK")})
  } catch (error) {

Share : facebook icon twitter icon
How to wait for getJSON to finish in a Mocha test?

How to wait for getJSON to finish in a Mocha test?

By : Peter Soltesz
Date : March 29 2020, 07:55 AM
around this issue The below files are within a project created with the generator-webapp generator for Yeoman. My script is working in the browser and returns the information from the JSON file but does not work in the test most of the time. The test succeeds sometimes which means the test hits a hiccup long enough to allow the getJSON to return the data in time. In my search, I found various resources, here are two sources that sounded like they should be solving my issue: a stackoverflow question and a blog. , You should use callback. For example:
code :
var source = (function() {
  var sourceData;

  function getData(done) {
    } else {
      $.getJSON("app/data/source.json", function(data) {
        sourceData = data;
  return {
    getData: getData
(function() {
  describe("Source Data", function() {
    describe("Data for External Modules", function() {
      it("returns the source data from a file", function(done){
How do I finish execution from within a promise in nodejs?

How do I finish execution from within a promise in nodejs?

By : Byung Ho Bret Lee
Date : March 29 2020, 07:55 AM
Hope this helps In node.js, the process will continue to run by itself if you have timers still running, servers still running or sockets still open.
You can manually exit your program at any time with process.exit() even if some of the above items are still running/open.
NodeJS fs.appendFile not working within promise in mocha

NodeJS fs.appendFile not working within promise in mocha

By : Noam Velleman
Date : March 29 2020, 07:55 AM
hope this fix your issue Your code is generally ignoring the fact that your fs calls are asynchronous. Promises are not magic. If you use code that is asynchronous but does not use promises, you need to do more than plop that code in a promise can call it done.
The easiest way to deal with the issue would be to use fs.writeFileSync and fs.appendFileSync instead of the calls you make. Otherwise, you should write your before like this:
code :
before(function(done) {
    if (!fs.existsSync("./log.csv")) {
        fs.writeFile("./log.csv", "Name; Time", done);
buildItem() {
    return this
        .then(result => {
            return new Promise((resolve, reject) => {
                fs.appendFile("./log.csv", `${item.name}; ${result.compileTime}`, (err) => {
                    if (err) {
How do I build a mocha test that waits for a process to finish first?

How do I build a mocha test that waits for a process to finish first?

By : rahman gulu
Date : March 29 2020, 07:55 AM
I hope this helps you . to @Evan, we found a solution yesterday...
There are two parts - one was the fact that the method we created to actually call our Java jar wasn't returning a Promise... so we changed it to:
code :
   console.log('calling: ' + cmdString);
return new Promise((resolve, reject) => {
    const wsdl2rest = exec(cmdString);
    wsdl2rest.stdout.on('data', function (data) {
        console.log(`stdout: ${data}`);
    wsdl2rest.stderr.on('data', function (data) {
        console.log(`stderr: ${data}`);
    wsdl2rest.on('close', function (code) {
        if (code === 0) {
            console.log(`wsdl2rest generated artifacts successfully`);
        } else {
            console.log(`stderr: ${code}`);
            console.log(`wsdl2rest did not generate artifacts successfully - please check the log file for details`);
describe('generator-camel:wsdl2rest', function () {
  describe('Should properly scaffold with config for Spring and wsdl2rest', function () {
    it('Should create the basic structure two ways', function () {
      basicProps.name = 'MyAppMock';
      basicProps.package = 'com.generator.mock';
      basicProps.camelVersion = '2.18.2';
      basicProps.camelDSL = 'spring';
      var wsdlPath = path.join(__dirname, '../test/address.wsdl');
      basicProps.wsdl = wsdlPath;
      basicProps.outdirectory = 'src/main/java';
      return helpers.run(path.join(__dirname, '../app'))
        .inTmpDir(function (dir) {
          var done = this.async(); // `this` is the RunContext object.
          fs.copy(path.join(__dirname, '../templates'), dir, done);
          basicProps.outdirectory = path.join(dir, 'src/main/java');
        .withOptions({ wsdl2rest: true })
        .withPrompts({ name: basicProps.name })
        .withPrompts({ camelVersion: basicProps.camelVersion })
        .withPrompts({ camelDSL: basicProps.camelDSL })
        .withPrompts({ package: basicProps.package })
        .withPrompts({ wsdl: basicProps.wsdl })
        .withPrompts({ outdirectory: basicProps.outdirectory })
        .then(() => { 
Testing promise callback in NodeJS with Mocha & Sinon

Testing promise callback in NodeJS with Mocha & Sinon

By : ramperj
Date : March 29 2020, 07:55 AM
I hope this helps you . The handler of the then() call will not be called during registration - only during the next event loop, which is outside your current test stack.
You'll have to perform the check from within the completion handler and notify mocha that your asynchronous code has completed. See also http://visionmedia.github.io/mocha/#asynchronous-code
Related Posts Related Posts :
  • How to get text from selected value in a dropdownlist which is js based
  • window is not defined angular universal third library
  • Angularjs ng-repeat stylization depending on previous value
  • Trying to implement Fittext.js
  • Calculate number of match in array Lodash
  • Jquery Smooth Scroll Using Offset.top
  • How to extract data to React state from CSV file using Papa Parse?
  • How to add unique links to google maps markers
  • How to use if condition in a tool bar in java script
  • Ajax filter in django not showing in HTML
  • data collection with Javascript
  • Rotate image on lightbox2 load
  • Prevent body from scrolling when a Pop-Up is open
  • How to copy files that do not need to be compiled in Gulp?
  • Array not assigned to variable? How does this work and what exactly is it doing?
  • Sorting associative array of objects in javascript
  • Changing Icon in Sap.m.tree having CustomTreeItem
  • Merge two array of objects based on a key
  • javascript in css not working
  • Passing only clicked element to onClick function - reactjs
  • React boilerplate doesn't load js files in the index.html
  • is Child service inside child component visible in the Parent component?
  • Check if data attribute value equals a string
  • How to get value of child tag of a button tag
  • How to access subjects of selected mails in Apple Mail using JavaScript?
  • How to get all dynamically set inline-style CSS in jQuery?
  • Error: Module "html" does not provide a view engine (Express)
  • Random Image in <Div> from array
  • Slider with touch function
  • ReactJS Component Architecture Problems / Nested Components or Single Component Manager
  • Javascript: Caching within Closure doesn't work
  • HTM5 Canvas Drawing App: How Do I Select The Color?
  • Assigning Events using HTML DOM
  • html5 getUserMedia() portrait mode
  • How to avoid 'headers already sent' within Promise chain?
  • Get a result from a react native app integrated into an existing android app
  • Why does the value of input field return undefined
  • How to get return object in jquery uploadFile method
  • Javascript string with arguments to single quotes
  • Understanding JS functions syntax (applies to other languages as well, I'm sure)
  • AngularJS Single Page App: Reference Error, ____ is not defined
  • whatwg-fetch new typescript 2.5.3
  • React.js - Array.unshift() not updating array on front-end
  • JavaScript localeCompare don't sort well [ "aaa-1.0", "aaa-1.1", "aaa-1.01", "aaa-11&
  • Mongoose handle validation error in a promise call and Express middleware
  • Building tree array of objects from flat array of objects
  • How to add a progress bar to file upload using javascript and ajax call?
  • JavaScript: is it permitted to override a standard built-in object?
  • Change the current page of an AJAX datatables
  • Array element is undefined even after pushing elements into it
  • onmousemove event not working
  • Chrome-Extension/JavaScript How to make all links on page have no effect?
  • Websocket issue Internet Explorer
  • sessionStorage value becomes null in other tab in AngularJS
  • Split URL from position x to the end in Javascript
  • How to set value of input field with NgIf in Angular 4
  • invalidStateError for second time screenshare on Chrome
  • How do you pass a value to the variable in a xhr.setRequestHeader?
  • I cant start nodemon on my windows 10
  • Nested if else jumps out from the main if else in javascript
  • shadow
    Privacy Policy - Terms - Contact Us © voile276.org