0

Here's my test in ./tests/homepage.test.js

context('Signup flow', () => {
    it('The happy path should work', () => {
        cy.visit('https://grazily.com/register');
        const random = Math.floor(Math.random() * 100000);
        cy.get('[data-testid=username]').type(`Tester${random}`);
        cy.get('[data-testid=email]').type(`user+${random}@realworld.io`);
        cy.get('[data-testid=password]').type('mysupersecretpassword');
        cy.get('[data-testid=signup-button]').click();
        cy.get('[data-testid=no-articles-here]', { timeout: 10000 }).should('be.visible');

Here's the file ./cypress/support/commands.js

import '@testing-library/cypress/add-commands';

tsconfig.json:

"compilerOptions": {
        "types": ["cypress", "@testing-library/cypress"],
...
}

I didn't make any other changes...and get this error when running npm t

I think t uses jest ./src so I'm not sure how to invoke cypress in ./tests/*test.js folder

Update:

Your pluginsFile is invalid: /home/ettinger/src/oblivion/Catalyze-frontend/cypress/plugins/index.js

Getting this error now with cypress run test

2 Answers 2

1

You're correct, npm t runs a predefined command specified in the "test" property of a package's "scripts" object.

//package.json
{
  ...
  "scripts": {
    "test": "jest"
  }
}

so you can either change "jest" to "cypress run" or add extra scripts, for example

//package.json
{
  ...
  "scripts": {
    "test": "jest",
    "e2e": "cypress run",
    "cy:open": "cypress open",
  }
}

or just run "npx cypress open" instead of "npm t".

BTW context(...) is valid in a Cypress test.

Sign up to request clarification or add additional context in comments.

6 Comments

Do you know what I should put in cypress.json? It fails saying file doesn't exist.
Your pluginsFile is invalid: /home/user/src/frontend/cypress/plugins/index.js -- i don't have this file.
If you install Cypress and run it (npx cypress open), it set's up both (empty) cypress.json and all requisite folders and files under /home/user/src/frontend/cypress.
how to i tell it to look in ./tests/**/*.test.js path? I got it working but it seems to be using TODO MVC code which is in ./cypress/ somewhere.
|
0

Getting this error now with cypress run test

If you are trying to run a specific test, add --spec

npm run cypress run --spec my-test.spec.js

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.