I need help refactoring this Cypress code
let stripe;
let bookService;
let images;
let moreDetails;
let checkoutDetails;
let wait;
before(() => {
cy.visit('/');
cy.fixture('stripe').then((data) => {
stripe = data;
});
cy.fixture('bookService').then((data) => {
bookService = data;
});
cy.fixture('images').then((data) => {
images = data;
});
cy.fixture('moreDetails').then((data) => {
moreDetails = data;
});
cy.fixture('wait').then((data) => {
wait = data;
});
});
I have tried
stripe = cy.fixture('stripe')
but it's returning an object { specWindow: ..., chainerId: ...}
It's ok to import fixtures at the to of the spec. You can use require()
to refactor the fixtures in the way you suggest,
let stripe = require('./cypress/fixtures/stripe.json')
let bookService = require('./cypress/fixtures/bookService.json')
let images = require('./cypress/fixtures/images.json')
let moreDetails = require('./cypress/fixtures/moreDetails.json')
let wait = require('./cypress/fixtures/wait.json')
before(() => {
cy.visit('/');
});