Today I Learned - Rocky Kev

TIL to refresh your Cypress test

POSTED ON:

TAGS:

Sometimes, you may have data lingering during a assertion.

Cypress is smart enough to clear it.
Sometimes it doesn't.

That can lead to a flakey test.

A good solution to clearly separate the tests and stop any application callbacks is to visit a "neutral" blank page. Unfortunately, using the cy.visit('about:blank') would not work.

The trick is this:

afterEach(() => {
cy.window().then((win) => {
win.location.href = 'about:blank'
})
})

Via
https://glebbahmutov.com/blog/visit-blank-page-between-tests/


Related TILs

Tagged:

TIL Scoping with Cypress

So you wanted to find a specific element called `heading`. But you have a BUNCH of elements called `heading`. By using `within()` helper, you can force it to only look inside `main` elements.

TIL MSW for mocking

MSW is a API mocking tool. Mock by intercepting requests on the network level. Seamlessly reuse the same mock definition for testing, development, and debugging.

TIL writing a clean function

Write an assert at the beginning of the function. Then, write down all the conditions that must be met.