cy.wait() 中的参数不完整

问题描述 投票:0回答:1

这是我面临的错误,我不明白为什么柏树等待函数没有完全获取参数

thenfunction(){} 断言错误 预计“19/0”等于“19/01/2028”

/* eslint-disable mocha/no-setup-in-describe,no-undef,mocha/no-skipped-tests */
// noinspection ES6ConvertRequireIntoImport
require('chai/register-expect');
const {basicResponseObj, bodyObjSearch2} = require("./common");


describe('Stubbed suite', function() {
    // Step 1: setup the application state
    beforeEach(function () {

        cy.clearCookies();
        cy.clearLocalStorage();
  
        cy.intercept('GET', '*/entries?usage=basic*', {body: basicResponseObj});
        cy.intercept('GET', '*/entries?usage=search*', {body: bodyObjSearch2}).as("searchResults");;
        cy.visit('search-test');
    });

    describe('Search by date range', function () {

        it("Fill filter and check query param is filled", () => {
            cy.get('#date-from').type("19/01/2028")
            cy.get('#date-to').type("19/01/2028")
            cy.get('#search-btn').click();
            cy.wait("@searchResults").then((req) => {
                expect(req.request.query.dateFrom).to.eq("19/01/2028");
              });
          });
   
          });
        })

 
javascript typescript cypress
1个回答
0
投票

可能不是

intercept
失败了,更有可能是
type
需要延迟或进行其他调整。

要进行检查,请在

type()

之后添加断言
cy.get('#date-from').type('19/01/2028')
cy.get('#date-from').invoke('val').should('eq', '19/01/2028')

然后添加延迟以使

.type()
稳定

cy.get('#date-from').type('19/01/2028', {delay, 100})
© www.soinside.com 2019 - 2024. All rights reserved.