Skip to content

Any sample repo on seeding data in Cypress? #188

Answered by kettanaito
neldeles asked this question in Q&A
Discussion options

You must be logged in to vote

Hey, @neldeles. Thanks for raising this.

To understand how to control your db between Cypress tests you need to understand how Cypress loads your app first. Cypress runner is its own process, while your running app is a different process (which you cy.visit). That's why the db you import in your Cypress test and in your app are two different db instances.

In order to change db on test runtime, you have to access the same instance that your app is accessing. That is possible if you persist that instance on window, since Cypress can share data between the tests and your app via window.

// your-app.js
const db = factory({ ... })

// Set the database reference on "window"
// so that Cypress t…

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
2 replies
@neldeles
Comment options

@kettanaito
Comment options

Answer selected by neldeles
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants