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

144
Views
Create a jest test to fail an async function which does not use await
async function isContentUser (userEmail, studentStatus) {
  const hasContentAccess = getContentCreatorAccess()
  const hasContentStudentStatus = studentStatus === CONTENT

  return hasContentStudentStatus || hasContentAccess
}

async function getContentCreatorAccess () {
  const { contentCreatorAccess } = await api.getContentCreatorPermission()

  return contentCreatorAccess
}

As you can see in isContentUser function, we're not awaiting getContentCreateAccess, but the below existing test pass, because hasContentAccess in the return value is a promise and we're awaiting the promise in the test.

And I want to create a PR which adds await before getContentCreatorAccess call, how can I come up with a test which works with await but not in the current code.

  it(`should return true if studentStatus is not Content but user has content permission`, async () => {
    api.getContentCreatorPermission.mockResolvedValue({
      contentCreatorAccess: true
    })

    expect(await isContentUser('email@gmail.com', 'Audit')).toBe(true)
  })
about 4 years ago · Juan Pablo Isaza
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!