@inrupt/solid-client / resource/mock

Module: resource/mock#

Functions#

mockContainerFrom#

mockContainerFrom(url): Unpromisify<ReturnType<typeof getSolidDataset>>

Warning

Do not use this function in production code. For use in unit tests.

This function initialises a new Container [[SolidDataset]] with metadata as though the Container has been retrieved from the given URL. The mock SolidDataset can be used in unit tests that require persisted Containers; e.g., unit tests that call [[isContainer]].

Parameters#

Name

Type

Description

url

string | Url

The URL from which the returned Container appears to be retrieved. The url must end in a slash.

Returns#

Unpromisify<ReturnType<typeof getSolidDataset>>

A mock SolidDataset that appears to be retrieved from the url.

Since

0.2.0

Defined in#

src/resource/mock.ts:79


mockFetchError#

mockFetchError(fetchedUrl, statusCode?, statusText?): FetchError

Warning

Do not use this function in production code. For use in unit tests.

This function initialises a new Error object with metadata as though the it was the result of getting a 404 when trying to fetch the Resource at the given URL. The mock Error can be used in unit tests that require functions that fetch Resources (like [[getSolidDataset]]) to fail.

Parameters#

Name

Type

Default value

Description

fetchedUrl

string

undefined

-

statusCode

number

404

Optional status code (defaults to 404) that caused the error.

statusText

string

"Not Found"

-

Returns#

FetchError

A mock Error that represents not having been able to fetch the Resource at url due to a 404 Response.

Since

1.1.0

Defined in#

src/resource/mock.ts:142


mockFileFrom#

mockFileFrom(url, options?): Unpromisify<ReturnType<typeof getFile>>

Warning

Do not use this function in production code. For use in unit tests.

This function initialises a new File with metadata as though the File has been retrieved from the given URL. The mock File can be used in unit tests that require persisted Files; e.g. unit tests that call [[getSourceUrl]].

Parameters#

Name

Type

Description

url

string | Url

The URL from which the returned File appears to be retrieved.

options?

Partial<{ contentType: undefined | string }>

-

Returns#

Unpromisify<ReturnType<typeof getFile>>

A mock File that appears to be retrieved from the url.

Since

0.2.0

Defined in#

src/resource/mock.ts:105


mockSolidDatasetFrom#

mockSolidDatasetFrom(url): Unpromisify<ReturnType<typeof getSolidDataset>>

Warning

Do not use this function in production code. For use in unit tests.

This function initialises a new [[SolidDataset]] with metadata as though the SolidDataset has been retrieved from the given URL. The mock SolidDataset can be used in unit tests that require persisted SolidDatasets; e.g., unit tests that call [[getSourceUrl]].

Parameters#

Name

Type

Description

url

string | Url

The URL from which the returned SolidDataset appears to be retrieved.

Returns#

Unpromisify<ReturnType<typeof getSolidDataset>>

A mock SolidDataset that appears to be retrieved from the url.

Since

0.2.0

Defined in#

src/resource/mock.ts:49