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.

Multiple files, multiple beforeEach, not all run

See original GitHub issue

Hello,

Current behavior:

I have 2 test files, both have their beforeEach with some commands that stub xhr requests. However, only one of the 2 beforeEach sections gets run. I do see it in the “Routes” section, but with 0 hits.

When I run both files in isolation, they work as expected.

Example command:

Cypress.Commands.add('mockGetActivationsData', (fixture = 'getActivations.json') => {
  cy.server();
  cy.route('GET', '**/**/business-units/*/activations', `fixture:activations/${fixture}`);
});

Desired behavior:

Each beforeEach section should allow commands to be fired to intercept xhr requests.

Steps to reproduce:

Create 2 test files. Each of them have a beforeEach section that call a command, that stubs a XHR request.

It works fine when I remove my command calls from every beforeEach section and duplicate them across every test.

Versions

  • cypress 2.1.0
  • chrome 66

Thanks

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:21 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
jennifer-shehanecommented, Dec 14, 2020

@zeralight Can you provide an example we can run completely? There’s a lot of things not included in your example that may be affecting the way it runs. You can edit our tests against our example.cypress.io website, which has some routing. Repo to fork: https://github.com/cypress-io/cypress-example-kitchensink

And opening a new issue would probably be best than this older issue.

0reactions
zeralightcommented, Dec 13, 2020

I am having a similar issue where the root describe isn’t running with nesting describes In some test, I delay a network request to test a loading state.

describe("...", () => {
  beforeEach(() => cy.setCookie(...));
  describe("...", () => {
    beforeEach(() => cy.route2("/foo", { delayMs: 2000 }).as("requestFoo"));

    it("...", () => {
      /* cy.setCookie() running and cy.route2() running */
      /* trigger action to request Foo */
      /* run asserts: OK */
      // cy.wait('@requestFoo')
    });
  });

  describe("...", () => {
   beforeEach(() => something());
    it("...", () => {
      /* something() running */
     /* cy.setCookie() not running */
    });
  });
});

When I uncomment the line // cy.wait(‘@requestFoo’), the issue disappears. Cypress: 5.3.0

Read more comments on GitHub >

github_iconTop Results From Across the Web

Sinon with multiple mocha test files - node.js
BefireEach must not call twice for one mocha test. Does importing multiple files call beforeEach twice? Can someone suggest any possible ...
Read more >
Writing and Organizing Tests
You can write placeholder tests in several ways as shown below, and Cypress knows NOT to run them. Cypress marks all the tests...
Read more >
Jest's 'beforeEach' may not be running the way you think it ...
So while I was expecting the top-beforeEach to have run 3 times total, once for each method within its block, it actually runs...
Read more >
Mocha seems to reuse required modules in multiple files. ...
Mocha running with multiple files seems not to cleanup after one file is done. Required modules are not reinitialised, but reused.
Read more >
JUnit 5 User Guide
Unlike previous versions of JUnit, JUnit 5 is composed of several different ... Unlike JUnit 4's @Test annotation, this annotation does not ......
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