mardi 26 janvier 2021

TestCafe mock backend data being overridden

I have a test that first logs in into a page, then selects a date range, on date picker, which queries an API to build a chart. I am trying to mock the data returned by the API with RequestMock I announce the mock outside of the test

let conversionMock = RequestMock()

with .onRequestTo and .respond then in my fixture I run

 fixture.requestHooks(conversionMock)

and finally when i select the datepicker time range in my test i run

await t.addRequestHooks(conversionMock)

When I run the test I see the data on the chart being populated for a split second, and then it's being overridden with the data the API actually returns. I suspect the reason for this is that the UI sends both OPTIONS and GET request to retrieve that data, and my mock only mocks the first request which is OPTIONS, and gets overridden by GET request. How do I make sure my data is not overridden and stays with me? I've tried calling multiple times in my test but that does not seem to help

await t.addRequestHooks(conversionMock) 

Aucun commentaire:

Enregistrer un commentaire