Skip to content

Commit 9a2a8cb

Browse files
authored
test: cover the case when the request is issued by cy.request() (#190)
relates-to #59
1 parent d1b6f6b commit 9a2a8cb

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

cypress/e2e/record-har.cy.ts

+19
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,25 @@ describe('Record HAR', () => {
4141
});
4242
});
4343

44+
// ADHOC: cy.request() sends requests to actual endpoints, bypassing the interceptor
45+
// For details please refer to the documentation at
46+
// https://docs.cypress.io/api/commands/request#cyrequest-sends-requests-to-actual-endpoints-bypassing-those-defined-using-cyintercept
47+
it.skip('records a request made by Cypress (not the tested app)', () => {
48+
cy.recordHar();
49+
50+
cy.request('/api/products');
51+
52+
cy.saveHar({ waitForIdle: true });
53+
54+
cy.findHar()
55+
.its('log.entries')
56+
.should('contain.something.like', {
57+
request: {
58+
url: /\/api\/products$/
59+
}
60+
});
61+
});
62+
4463
// ADHOC: .mjs files are excluded as Cypress forces ts-node to use the 'commonjs' module format. Covered by unit tests.
4564
// For details please refer to https://github.com/cypress-io/cypress/blob/e6b2466f7b219a86da46c1ac720432ef75193ca4/packages/server/lib/plugins/child/ts_node.js#L25
4665
['.js', '.ts', '.cjs'].forEach(ext =>

cypress/support/e2e.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ like.extend({
1919
Cypress.Commands.add('findHar', (fileName?: string) =>
2020
cy
2121
.readFile(fileName ?? Cypress.spec.name.replace('.ts', '.har'))
22-
.then(data => cy.wrap<Har>(JSON.parse(data)))
22+
.then(data => cy.wrap<Har>(data ? JSON.parse(data) : undefined))
2323
);
2424

2525
// check a file/folder existence

0 commit comments

Comments
 (0)