createMockSender
Package
Installation
- npm
- Yarn
- pnpm
npm install @rpldy/mock-sender
yarn add @rpldy/mock-sender
pnpm add @rpldy/mock-sender
Details
type MockSender = {
update: (updated: MockOptions) => void;
send: SendMethod;
};
type createMockSender = (option: MockOptions) => MockSender;
- See: SendMethod
- See: MockOptions
Options
Name (* = mandatory) | Type | Default | Description |
---|---|---|---|
delay | number | 500 | time in ms for mocked upload to take |
fileSize | number | undefined | file size of the mocked upload, used for progress calculation |
progressIntervals | number[] | [10, 25, 50, 75, 90] | mock intervals (percentages) to emit progress events at |
response | any | { mock: true, success: true } | mock response for upload request |
responseStatus | number | 200 | upload request status code |
isSuccessfulCall | IsSuccessfulCall | undefined | callback 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>
);