I started to use Cypress a few days ago and i'm already struggling with a simple command such as visit
.
To figure out what happens, i have created a classic create react app
yarn create react-app cypress-test-react
then cypress dependencies
cd cypress-test-react && yarn add cypress --dev
As i'm using Linux, i run this command too:
apt-get install libgtk2.0-0 libgtk-3-0 libgbm-dev libnotify-dev libgconf-2-4 libnss3 libxss1 libasound2 libxtst6 xauth xvfb
I have implemented something i saw
I expect some missing packages in my local env but i can't find out what is it.
If some of you already manage this issue, i would really appreciate some help :). I'm available for more informations
Here is my local config:
OS: Ubuntu 18.04.4 LTS x86_64
yarn: 1.22.4
node: v15.14.0
CodePudding user response:
Basically, yarn cypress open-ct ...
is for component testing.
You can't do cy.visit()
in a component test, it's used for e2e tests.
Which way do you want to test - the whole page, or a single react component?
If e2e, use yarn cypress open
.
CodePudding user response:
You can try passing failOnStatusCode: false
in cy.request()
. This will not fail your test if it doesn't get 2xx or 3xx response codes.
describe('Create react app home', () => {
beforeEach(() => {
cy.request({
url: 'http://localhost:3000',
failOnStatusCode: false,
}).then((response) => {
if (response.isOkStatusCode) {
cy.visit('http://localhost:3000')
} else {
cy.visit('http://localhost:3000')
}
})
})
it('renders learn react link', () => {
cy.contains('Learn React')
})
})