Skip to content

Lupa API Reference / network / Network

Class: Network

Defined in: src/network/index.ts:15

The developer-facing API for network interception and mocking. Available in browser tests via the network fixture on the TestContext.

Constructors

Constructor

new Network(): Network

Returns

Network

Methods

mock()

Call Signature

mock(match, respond): Promise<NetworkInterceptor>

Defined in: src/network/index.ts:39

Registers a new network mock to intercept requests matching the provided criteria. Intercepted requests can be bypassed, stubbed with static payloads, or handled by dynamic closures.

Note: All mocks created during a test are automatically restored when the test finishes.

Parameters
match

NetworkMatch

The matching criteria (e.g. URI string or request options).

respond

NetworkRespondPayload | NetworkRespondDynamic

The static payload or dynamic closure used to fulfill the matched request.

Returns

Promise<NetworkInterceptor>

A NetworkInterceptor to manage the mock and assert against captured requests.

Example
ts
test('handles 500 error', async ({ network }) => {
  const mock = await network.mock('/api/users', {
    status: 500,
    body: { error: 'Internal Server Error' }
  })

  button.click()
  await mock.assert.calledOnce()
})

Call Signature

mock(options): Promise<NetworkInterceptor>

Defined in: src/network/index.ts:63

Registers a new network mock to intercept requests using a single configuration object. Intercepted requests can be bypassed, stubbed with static payloads, or handled by dynamic closures.

Note: All mocks created during a test are automatically restored when the test finishes.

Parameters
options

NetworkMockOptions

The configuration defining the matching criteria and response behavior.

Returns

Promise<NetworkInterceptor>

A NetworkInterceptor to manage the mock and assert against captured requests.

Example
ts
test('handles 500 error', async ({ network }) => {
  const mock = await network.mock({
    match: '/api/users',
    respond: { status: 500, body: { error: 'Internal Server Error' } }
  })

  button.click()
  await mock.assert.calledOnce()
})