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

200
Views
jasmine test that function does return a resolved promise

Code:

var cartModule = (function() {  
  checkOverbook: function(skip) {
    return new Promise(function(resolve, reject) {
      if (skip) {
        addItemPromiseResolver = resolve;
      } else {
        resolve({"continue_add":true})
      }
    })
  },
})();

I'd like to test that when cartModule.checkOverbook is called with skip = true, that the promise is resolved, but that when it's called with skip = false it is not resolved. Is this possible/recommended, or should I just test this in the context of the consuming function?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I think it is possible, you could possibly do something like so:

it('resolves if skip is false', async () => {
  const skip = false;
  await expectAsync(cartModule.checkOverbook(skip)).toBeResolvedTo({ 'continue_add': true });
});

it('changes addItemPromiseResolver to resolve if skip is true', () => {
  expect(addItemPromiseResolver).toBeUndefined();
  const skip = true;
  // just call the function
  cartModule.checkOverbook(skip);
  expect(addItemPromiseResolver).not.toBeUndefined();
});
about 4 years ago · Juan Pablo Isaza 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!