Невозможно использовать cy.server () с препроцессором cypress-cucumber- - PullRequest
1 голос
/ 02 апреля 2019

Когда я пытаюсь запустить cy.server (), чтобы смоделировать http-запросы, которые выполняются как часть тестов, я получаю следующую ошибку:

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

Я не знаю, как заставить это работать. Это мой код:

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)
})

1 Ответ

2 голосов
/ 02 апреля 2019

Вам не хватает контекста it () для Cypress. Попробуйте это:

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

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

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

  it('description of the it', function () {
    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)
    })
  })
...