Allow handling preflight requests automatically in RequestMock
See original GitHub issueWhat is your Scenario?
I’m trying to intercept the response from a certain public API and return custom response, but even with recommended headers to allow all I keep getting CORS issues.
What is the Current behavior?
I’m getting "RequestMock: CORS validation failed for a request specified as { url: “Url I use” }
What is the Expected behavior?
I should not get any CORS issues while using ‘access-control-allow-origin’: ‘*’ response headers
What is your public website URL? (or attach your complete example)
What is your TestCafe test code?
Your complete configuration file
import { RequestMock } from ‘testcafe’;
const mockExample = RequestMock().onRequestTo(‘https://services.repsly.com/LocalizationService/Dictionary/GetDefaults’) .respond({ response: ‘success’ }, 200, { ‘access-control-allow-origin’: ‘*’ })
fixtureTestcafe RequestMock issue
.beforeEach(async t => {
await t
.maximizeWindow()
});
test.requestHooks(mockExample)(‘DOESNT WORK - CORS origin error’, async t => { await t.navigateTo(‘https://user.repsly.com’); });
Your complete test report
{ “startTime”: “2022-09-28T12:27:32.951Z”, “endTime”: “2022-09-28T12:27:50.714Z”, “userAgents”: [ “Chrome 105.0.0.0 / Windows 10” ], “passed”: 1, “total”: 1, “skipped”: 0, “fixtures”: [ { “name”: “Testcafe RequestMock issue”, “path”: “E:\Projekti\TestCafeRepsly\testcafe\templates\QAB-12515-RequestMockCorsIssue.spec.ts”, “meta”: {}, “tests”: [ { “name”: “DOESNT WORK - CORS origin error”, “meta”: {}, “errs”: [], “durationMs”: 17719, “unstable”: false, “screenshotPath”: null, “skipped”: false } ] } ], “warnings”: [ “The "src" and "browsers" options from the configuration file will be ignored.”, “RequestMock: CORS validation failed for a request specified as { url: "https://services.repsly.com/LocalizationService/Dictionary/GetDefaults\” }" ] }
Screenshots
No need, everything is in the console.
Steps to Reproduce
- Just run the test example provided here and observe the results
TestCafe version
2.0.1
Node.js version
16.15.0
Command-line arguments
testcafe chrome pathToTest -r spec
Browser name(s) and version(s)
chrome 105
Platform(s) and version(s)
Windows 10
Other
No response
Issue Analytics
- State:
- Created a year ago
- Comments:5
Top GitHub Comments
No, you can chain only TestСafe’s own methods. The correct way is to configure
nock
in thefixture.before
hook or before the whole test run.Thx @miherlosev for suggestion. Is there any example how to use and chain nock library within testcafe block structure? I liked that I could chain test block like: “test.requestHooks(mockExample)”; is there equivalent using nock? Also, ALL of our requests/responses are the same as the public example I provided, so we will use nock once we figure out how to properly use and chain it 😃