npm install cypress # 설치
./node_modules/.bin/cypress open # cypress 오픈
[counter.cy.js]
최초 카운트 값 0인지 확인하는 코드
describe("example counter app", () => {
//테스트 전에 항상 실행해야 하는 것
beforeEach(() => {
cy.visit("<http://127.0.0.1:5500/index.html>");
});
//테스트 코드
it("최초에 카운터 값을 0으로 표시", () => {
cy.get("#value").invoke("text").should("eq", "0");
});
});
결과

버튼을 눌렀을 때 +1 증가하는 지 확인하는 코드
it("+ 버튼을 클릭 시 count가 1 가", () => {$
cy.get("#value")
.invoke("text")
.then((value) => {
const preValue = Number(value);
cy.get(".increase-btn").click();
cy.get("#value")
.invoke("text")
.should("eq", String(preValue + 1));
});
});
결과
