I am relatively new to Testcafé testing framework that claims for:
End-to-end testing, simplified No WebDriver required. No manual timeouts needed. Cross-browser testing out-of-the-box.
I must admit the syntax is a bit confusing at first, but you get quickly up to speed, thanks to useful documentation, what is quite rewarding.
I do care a great deal about Progressive
enhancement. This is my go to approach to build
components and experiences for the web.
If you are doing Agile developement, this fits perfectly as you could first ship a basic working experience and in the next iteration the enhanced experience.
What I needed
In order to gain confidence upon the fact that both my basic and enhanced experiences are working, I needed to be able to:
necessary for the enhancement should be an external file.
resolving to a
404 status code.
To perform this lie, we can use Testcafé Request Mock feature.
A request mocker that intercepts requests to a web resource and emulates the response.
The small code snippet below led me to success:
This is how you instanciate the mock to make any requested
.js file in the
page under test to respond with a
404 Not Found.
Now you can use this mock in your tests as below:
The magic operates through the call to
.requestHooks() function that takes our
Request Mock as argument and applies it the page under test.