TheBrainFamily / cypress-cucumber-example

Example of using Cypress with Cucumber
MIT License
195 stars 120 forks source link

Unable to use cy.server() with Step definition syntax #6

Closed orbmis closed 5 years ago

orbmis commented 5 years ago

When I try to run cy.server() in order to mock http requests that are executed as part of the tests, I get the following error:

Uncaught CypressError: Cannot call "cy.server()" outside a running test.....

I don't know how to get this to work. This is my code:

import { Given, Then } from 'cypress-cucumber-preprocessor/steps'

beforeEach(() => {
  cy.server()

  cy.route({
    method: 'GET',
    url: '/',
    response: []
  })
})

const url = 'http://localhost:8080'

Given('I click the big button', () => {
  cy.visit(url)
  cy.get('.btn').click()
})

Then('I can get the MOTD', (title) => {
  cy.title().should('include', title)
})
orbmis commented 5 years ago

Closing this as it is in the wrong repo - apologies. Will re-open in correct repo.