@decoraxios/mock
v0.5.0
Published
MSW-powered mock package for Decoraxios
Downloads
291
Readme
@decoraxios/mock
@decoraxios/mock adds MSW-powered mocking to Decoraxios while keeping the same async call shape as real requests.
If you need WebSocket mocking, use @decoraxios/mock-ws.
Install
npm install decoraxios @decoraxios/mock axios mswIncludes
@MockMockAPIHttpResponsehttp
Example
import { Get, HttpApi, type ApiCall } from 'decoraxios';
import { HttpResponse, Mock, MockAPI } from '@decoraxios/mock';
await MockAPI.on();
@HttpApi('https://api.example.com/users')
class UserApi {
@Get('/')
@Mock({
default: () => HttpResponse.json([{ id: '1', name: 'Ada' }]),
empty: () => HttpResponse.json([]),
})
listUsers(): ApiCall<Array<{ id: string; name: string }>> {
return undefined as never;
}
}
MockAPI.useNextHandler('empty');