Skip to main content

createMockSender

Package

Installation

npm install @rpldy/mock-sender

Details


type MockSender = {
update: (updated: MockOptions) => void;
send: SendMethod;
};

type createMockSender = (option: MockOptions) => MockSender;

Options

Name (* = mandatory)TypeDefaultDescription
delaynumber500time in ms for mocked upload to take
fileSizenumberundefinedfile size of the mocked upload, used for progress calculation
progressIntervalsnumber[][10, 25, 50, 75, 90]mock intervals (percentages) to emit progress events at
responseany{ mock: true, success: true }mock response for upload request
responseStatusnumber200upload request status code
isSuccessfulCallIsSuccessfulCallundefinedcallback to use to decide whether upload response is succssful or not
info

isSuccessfulCall receives a mock XHR object with the mock status, response, and headers

Usage

import Uploady from "@rpldy/uploady";
import UploadButton from "@rpldy/upload-button";
import { getMockSenderEnhancer } from "@rpldy/mock-sender";

const mockSenderEnhancer = getMockSenderEnhancer({
delay: 1500,
progressIntervals: [20, 40, 75, 80, 90, 99]
});

const App = () => (
<Uploady
enhancer={mockSenderEnhancer}
>
<UploadButton />
</Uploady>
);