Skip to content

Commit 7cc965e

Browse files
committed
Ensure support of network matchers
1 parent e3848b9 commit 7cc965e

8 files changed

Lines changed: 898 additions & 863 deletions

File tree

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import { browser } from '@wdio/globals'
2+
3+
describe('Network Matchers', () => {
4+
let mock: WebdriverIO.Mock
5+
6+
beforeAll(async () => {
7+
mock = await browser.mock('https://webdriver.io/api/foo', {
8+
method: 'POST'
9+
})
10+
mock.respond({ success: true }, {
11+
statusCode: 200,
12+
headers: { Authorization: 'bar' }
13+
})
14+
15+
await browser.url('https://webdriver.io/')
16+
17+
await browser.execute(async () => {
18+
await fetch('https://webdriver.io/api/foo', {
19+
method: 'POST',
20+
headers: { Authorization: 'foo' },
21+
body: JSON.stringify({ title: 'foo', description: 'bar' })
22+
})
23+
})
24+
})
25+
26+
it('should assert on network calls', async () => {
27+
await expect(mock).toBeRequested()
28+
await expect(mock).toBeRequestedTimes(1)
29+
30+
// Detailed check (simplified to match available Bidi fields)
31+
await expect(mock).toBeRequestedWith({
32+
url: 'https://webdriver.io/api/foo',
33+
method: 'POST'
34+
})
35+
})
36+
37+
it('should support asymmetric matchers', async () => {
38+
await expect(mock).toBeRequestedWith(expect.objectContaining({
39+
method: 'POST'
40+
}))
41+
})
42+
43+
it('should support jasmine asymmetric matchers', async () => {
44+
await expect(mock).toBeRequestedWith(jasmine.objectContaining({
45+
method: 'POST'
46+
}))
47+
})
48+
})
49+
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { browser } from '@wdio/globals'
2+
3+
describe('Network Matchers', () => {
4+
it('should assert on network calls', async () => {
5+
const mock = await browser.mock('https://webdriver.io/api/foo', {
6+
method: 'POST'
7+
})
8+
mock.respond({ success: true }, {
9+
statusCode: 200,
10+
headers: { Authorization: 'bar' }
11+
})
12+
13+
await browser.url('https://webdriver.io/')
14+
15+
await browser.execute(async () => {
16+
await fetch('https://webdriver.io/api/foo', {
17+
method: 'POST',
18+
headers: { Authorization: 'foo' },
19+
body: JSON.stringify({ title: 'foo', description: 'bar' })
20+
})
21+
})
22+
23+
await expect(mock).toBeRequested()
24+
await expect(mock).toBeRequestedTimes(1)
25+
26+
// Detailed check (simplified to match available Bidi fields)
27+
await expect(mock).toBeRequestedWith({
28+
url: 'https://webdriver.io/api/foo',
29+
method: 'POST'
30+
})
31+
32+
// Asymmetric matcher as argument (Validating the specific fix)
33+
await expect(mock).toBeRequestedWith(expect.objectContaining({
34+
method: 'POST'
35+
}))
36+
})
37+
})
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { browser } from '@wdio/globals'
2+
3+
describe('Network Matchers', () => {
4+
it('should assert on network calls', async () => {
5+
const mock = await browser.mock('https://webdriver.io/api/foo', {
6+
method: 'POST'
7+
})
8+
mock.respond({ success: true }, {
9+
statusCode: 200,
10+
headers: { Authorization: 'bar' }
11+
})
12+
13+
await browser.url('https://webdriver.io/')
14+
15+
await browser.execute(async () => {
16+
await fetch('https://webdriver.io/api/foo', {
17+
method: 'POST',
18+
headers: { Authorization: 'foo' },
19+
body: JSON.stringify({ title: 'foo', description: 'bar' })
20+
})
21+
})
22+
23+
await expect(mock).toBeRequested()
24+
await expect(mock).toBeRequestedTimes(1)
25+
26+
// Detailed check (simplified to match available Bidi fields)
27+
await expect(mock).toBeRequestedWith({
28+
url: 'https://webdriver.io/api/foo',
29+
method: 'POST'
30+
})
31+
32+
// Asymmetric matcher as argument (Validating the specific fix)
33+
await expect(mock).toBeRequestedWith(expect.objectContaining({
34+
method: 'POST'
35+
}))
36+
})
37+
})

test-types/jasmine-global-expect-async/types-jasmine_async.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,10 @@ describe('type assertions', () => {
518518
postData: wdioExpect.objectContaining({ released: true, title: wdioExpect.stringContaining('foobar') }),
519519
response: (r: { data: { items: unknown[] } }) => Array.isArray(r) && r.data.items.length === 20
520520
})
521+
522+
expectPromiseVoid = expectAsync(promiseNetworkMock).toBeRequestedWith(jasmine.objectContaining({
523+
method: 'POST'
524+
}))
521525
})
522526

523527
it('should have ts errors when typing to void', async () => {

test-types/jasmine/types-jasmine.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,10 @@ describe('Jasmine expectAsync type agumentations', () => {
412412
postData: wdioExpect.objectContaining({ released: true, title: wdioExpect.stringContaining('foobar') }),
413413
response: (r: { data: { items: unknown[] } }) => Array.isArray(r) && r.data.items.length === 20
414414
})
415+
416+
expectPromiseVoid = expectAsync(promiseNetworkMock).toBeRequestedWith(jasmine.objectContaining({
417+
method: 'POST'
418+
}))
415419
})
416420

417421
it('should have ts errors when typing to void', async () => {

0 commit comments

Comments
 (0)