programing

Chainable...의 매개 변수 유형 키에 인수 유형 문자열을 할당할 수 없습니다.사이프레스에서

sourcejob 2023. 7. 3. 22:49
반응형

Chainable...의 매개 변수 유형 키에 인수 유형 문자열을 할당할 수 없습니다.사이프레스에서

Cypress에서 9.0.0 업데이트 후 다음 오류가 발생했습니다.

Chainable...의 매개 변수 유형 키에 인수 유형 문자열을 할당할 수 없습니다.형식 문자열은 "and" | "as" | "blur" | "check" | "children" | "clearCookie" | "clearCookie" | "clearCookies" | "clearLocalStorage" | "클릭" | "클릭" | "클럭" | ...모든 사용자 지정 명령에 영향을 주는 "intercept" 유형에 유형 문자열을 할당할 수 없습니다.

누가 저 좀 도와주시겠어요?내 사용자 지정 명령

버전 9.0.0부터는 사용자 지정 명령을 선언해야 합니다.9.0.0(변경 중인 6번째 글머리 기호)에 대한 변경 로그를 참조하고 여기에서 선언된 사용자 지정 체인을 기반으로 현재 입력 중인 사용자 지정 명령에 대한 구체적인 정보를 확인합니다.

또한 사용자 지정 명령을 추가하고 올바르게 선언하는 방법에 대해서도 이 레시피를 참조하십시오.

사용자 지정 명령을 위해 이 파일을 추가합니다.cypress/support/index.d.ts다음 코드를 사용합니다.

/// <reference types="cypress" />

declare namespace Cypress {
    interface Chainable<Subject = any> {
        /**
         * Custom command to ... add your description here
         * @example cy.clickOnMyJourneyInCandidateCabinet()
         */
        clickOnMyJourneyInCandidateCabinet(): Chainable<null>;
    }
}

지지/index.d.ts로

declare namespace Cypress {
  interface Chainable<Subject = string> {
    preventSubmit(form: string): Chainable<Element>;
  }
}

지원하는/명령하는

Cypress.Commands.add("preventSubmit", (form) => {
  cy.get(form).then((form$) => {
    form$.on("submit", (e) => {
      e.preventDefault();
    });
  });
  cy.log(`prevent default submit to '${form}'`);
});

스펙/테스트 js로

describe("MyTest", () => {
  ...
  it("Test 1", () => {
    ...
    cy.preventSubmit("form");
    cy.get("form").submit();
  }
}

언급URL : https://stackoverflow.com/questions/69927966/argument-type-string-is-not-assignable-to-parameter-type-keyof-chainable-in-c

반응형