main

mattermost/focalboard

Last updated at: 29/12/2023 09:42

fetchMock.ts

TLDR

This file contains a class called FetchMock that provides two methods for mocking fetch requests in unit tests.

Methods

fn

This method is a Jest mock function. It returns a Promise that resolves to an empty Response.

jsonResponse(json: string): Promise<Response>

This method returns a Promise that resolves to a Response object with the specified JSON payload.

Classes

FetchMock

This class provides methods for mocking fetch requests in unit tests.

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.

class FetchMock {
    static fn = jest.fn(async () => {
        const response = new Response()
        return response
    })

    static async jsonResponse(json: string): Promise<Response> {
        const response = new Response(json)
        return response
    }
}

export {FetchMock}