I did it like so:
- Create a module that is loaded only when you are running integration tests
- In this module, create a client side function
createTestUserthat calls Meteor’sAccount.createUserwith credentials you wish to use, so a fresh user is created for each test - Assign this function to
window - Create a Cypress command
login, something like this:
function login(win) {
win.createTestUser().then(() => win.appReady = true);
}
Cypress.Commands.add('login', () => {
cy.visit('/'); // load the app
cy.window().then(login); // create user
cy.window().should('have.property', 'appReady', true); // wait for the user to get created
});
- Use this command in the
beforeEachhooks of your Cypress tests