Test
[Cypress] Api test stub 하기 with intercept
w00se
2022. 3. 17. 01:29
cypress의 Network Requests
intercept 메서드를 활용하면 Api 요청 부분을 stub할 수 있다.
- 사용 예시: api 요청부분을 stub으로 처리하고 응답 결과로 dummy 데이터 반환하기
- 'https://abcd.efg.com/*'을 사용하면 url host가 abcd.efg.com으로 시작하는 모든 요청에 대한 응답을 stub한다.
- 공식문서에 의하면 아래 예시처럼 fixture를 단축해서 사용할 수 있다.
cy.intercept('https://abcd.efg.com/*', { fixture: 'dummyData.json' }).as('requestData'); cy.wait('@requestData');