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.

Before and beforeEach in supportFile - unexpected behavior during 'run all specs'

See original GitHub issue

Current behavior:

before and beforeEach executed from support file seems unlogical. As docs described, beforeEach runs before each test in each spec file. In this way, I expect to see before hook before starting each spec file. But it doesn’t, it runs only once.

Снимок экрана 2019-07-12 в 11 22 22

Desired behavior:

Seems like more clear to run before hook before each spec file, like each before hook from spec file does.

Steps to reproduce: (app code and test code)

I just pasted this piece of code into support/index.js

before(() => {
    cy.log('Run before');
});

beforeEach(() => {
    cy.log('Run before each');
});

Versions

Cypress: 3.3.1 MacOs: 10.14.5 Google Chrome: 75.0.3770.100

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:1
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
Songyu-Wangcommented, Jul 13, 2019

Oh, I see the issue now… sorry I didn’t realize there are two before defined by you. Sorry… please ignore whatever I said… I think you are right

1reaction
Songyu-Wangcommented, Jul 12, 2019

you can also put before() and beforeeach() inside spec files…

Read more comments on GitHub >

github_iconTop Results From Across the Web

Be careful when running all specs together - Gleb Bahmutov
Be careful when running all specs together. A common mistake when using beforeEach hooks in Cypress specs. Example application; Support file ...
Read more >
How to run before on most cypress tests but not all
The official Cypress documentation on hooks has a great example showing where before and beforeEach hooks are placed in the describe and it ......
Read more >
Writing and Organizing Tests - Cypress Documentation
You can define behaviors in a before or beforeEach within any of the cypress/support files: beforeEach(() => { cy.log('I run before every test...
Read more >
2.2.1.8 - Setup and Teardown
These Triangle objects were all different, but what would happen if we needed to instantiate the same Triangle object for many tests?
Read more >
Mocha - API Manual
Mocha tests run serially, allowing for flexible and accurate reporting, ... all tests in this block }); beforeEach(function() { // runs before each...
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