Hello,
I’m trying to write a test with mockRequest
involved. I just set up a small project and wrote a basic test like follows:
Feature('Search');
const response = [{"phrase": "test"}, {"phrase": "hello"}, {"phrase": "world"}, {"phrase": "duckduckgo"}];
Scenario('search in Duckduckgo', ({I}) => {
I.amOnPage('https://duckduckgo.com/');
I.mockRequest('GET', 'https://duckduckgo.com/ac/*', response);
I.fillField('#search_form_input_homepage', 'hello');
});
But when I run yarn codeceptjs run --steps --debug --verbose
I’m getting the following:
❯ yarn codeceptjs run --steps --debug --verbose
CodeceptJS v3.0.2
Using test root "/home/sergey/dev/codecept-example"
Helpers: Puppeteer, MockRequestHelper
Plugins: screenshotOnFail, retryFailedStep, tryTo
Search --
[1] Starting recording promises
search in Duckduckgo
I am on page "https://duckduckgo.com/"
› [Url] https://duckduckgo.com/
I mock request "GET", "https://duckduckgo.com/ac/*", [{"phrase":"test"},{"phrase":"hello"},{"phras…
[1] Retrying... Attempt #2
[1] Retrying... Attempt #3
[1] Retrying... Attempt #4
[1] Retrying... Attempt #5
[1] Retrying... Attempt #6
[1] Error | TypeError: Cannot read property 'apply' of undefined
[1] Error | TypeError: Cannot read property 'apply' of undefined
[1] Error | TypeError: Cannot read property 'apply' of undefined
[1] Starting <teardown> session
[1] <teardown> Stopping recording promises
› <screenshotOnFail> Test failed, try to save a screenshot
› Screenshot is saving to /home/sergey/dev/codecept-example/output/search_in_Duckduckgo.failed.png
✖ FAILED in 5857ms
[2] Starting recording promises
Polly was not disconnected, Puppeteer is already closed
-- FAILURES:
1) Search
search in Duckduckgo:
Cannot read property 'apply' of undefined
I’m probably doing something wrong. Though I can’t figure out what exactly.
The full project can be found here.