question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Assertion failure in async test case does not fail test overall

See original GitHub issue

Related issues

Current behavior:

The assertion fails(in red) but the overall test still passes,

Desired behavior:

Asserts with cy work in async test case

Steps to reproduce: (app code and test code)

Use the following testing code with async and notice the test succeeds.

https://github.com/MadLittleMods/cypress-test-tiny/pull/1/files

const generateFixtures = function() {
  return new Promise(resolve => {
    setTimeout(() => {
      resolve("bar");
    }, 1000);
  });
};

describe("Some page", function() {
  it("shows something", async function() {
    const fixtures = await generateFixtures();

    cy.visit(`http://google.com/?foo=${fixtures}`);

    cy.contains("somethingthatodoesNOTexist");
  });
});

Versions

  • Cypress 3.4.0
  • Node v10.15.1
  • Windows 10

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:12
  • Comments:53 (22 by maintainers)

github_iconTop GitHub Comments

11reactions
damaoncommented, Nov 13, 2019

What is the point of having testing tool that doesn’t even assert properly? This should have P1

Can someone guide me to related code?

8reactions
meissadiacommented, Feb 22, 2020

I believe most of these failures are due to the assertion failing AFTER the test has successfully finished, read https://www.cypress.io/blog/2020/01/16/when-can-the-test-stop/

Very helpful blog post @bahmutov! This approach solved my issue:

it('waits for window confirm to happen using variable', () => {
  cy.visit('index.html')
  let called

  cy.on('window:confirm', (message) => {
    expect(message).to.equal('Are you sure?')
    called = true
  })

  cy.get('#click').click()
  // test automatically waits for the variable "called"
  cy.wrap(null).should(() => {
    expect(called).to.be.true
  })
})
Read more comments on GitHub >

github_iconTop Results From Across the Web

mocha test passes even when assertion fail if async function ...
If an exception is thrown by the test case (i.e., by the assertion library), the test is deemed to have failed.
Read more >
Assert | Node.js v19.3.0 Documentation
If asyncFn is a function and it throws an error synchronously, assert.doesNotReject() will return a rejected Promise with that error. If the function...
Read more >
Mocha - the fun, simple, flexible JavaScript test framework
Mocha is a feature-rich JavaScript test framework running on Node.js and in the browser, making asynchronous testing simple and fun. Mocha tests run ......
Read more >
unittest — Unit testing framework — Python 3.11.1 ...
test fixture. A test fixture represents the preparation needed to perform one or more tests, and any associated cleanup actions. This may involve,...
Read more >
Assert | Basic Guides | Guides | Docs - TestCafe
test ('Button click', async t => { const btn = Selector('#btn'); await t .click(btn) // A regular assertion fails immediately, but TestCafe retries...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found