Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

266
Views
getById() returns undefined Promise

I have the following class method in my Sequelize model:

getById(id) {
      return new Promise((resolve, reject) => {
          var Conference = sequelize.models.conference;
          Conference.findById(id).then(function(conference) {
              if (_.isObject(conference)) {
                  resolve(conference);
              } else {
                  throw new ResourceNotFound(conference.name, {id: id});
              }
          }).catch(function(err) {
              reject(err);
          });
      });
  }

Now I want to test my method with chai. But now when I do Conference.getById(confereceId) I get the following back:

Promise {
  _bitField: 0,
  _fulfillmentHandler0: undefined,
  _rejectionHandler0: undefined,
  _promise0: undefined,
  _receiver0: undefined }

Is this right and how do I assert the result of it with chai?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Your Conference.getById(confereceId) call returns a promise, so you should resolve the promise first via then, and assert the result of it with chai like this:

const assert = require('chai').assert;

Conference
  .getById(confereceId)
  .then(conf => {
    assert.isObject(conf);
    // ...other assertions
  }, err => {
    assert.isOk(false, 'conference not found!');
    // no conference found, fail assertion when it should be there
  });
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!