@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.

since 0.2.0

Parameters

Name

Type

Description

url

Url | UrlString

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.


mockFetchError

mockFetchError(fetchedUrl, statusCode?): 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.

since 1.1.0

Parameters

Name

Type

Default value

Description

fetchedUrl

UrlString

undefined

-

statusCode

number

404

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

Returns

FetchError

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


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.

since 0.2.0

Parameters

Name

Type

Description

url

Url | UrlString

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

options?

Partial<Object>

-

Returns

Unpromisify<ReturnType<typeof getFile>>

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


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.

since 0.2.0

Parameters

Name

Type

Description

url

Url | UrlString

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.