Skip to content

Mocha doesn't run async code properly have to add wrapper

Closed

Description

  it('should run async code', function() {

    (async function main() {

      let upload = await Upload.findOne({
        uploadUrl: {$exists: true},
        visibility: 'public'
      }).populate('checkedViews uploader').exec();

      console.log(upload);

      upload.should.be.an('object');

    })();

  });

Otherwise I get

Error: timeout of 2000ms exceeded. Ensure the done() callback is being called in this test.

If I try and change the it function to an async function. How can I use async/await?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions