Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ssssota/connect-web-mock-interceptor
Mock utility for connect-web.
https://github.com/ssssota/connect-web-mock-interceptor
connect-web grpc interceptor mock
Last synced: 15 days ago
JSON representation
Mock utility for connect-web.
- Host: GitHub
- URL: https://github.com/ssssota/connect-web-mock-interceptor
- Owner: ssssota
- License: apache-2.0
- Created: 2023-01-29T10:09:41.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2023-01-29T13:22:41.000Z (almost 2 years ago)
- Last Synced: 2024-10-11T12:15:10.303Z (3 months ago)
- Topics: connect-web, grpc, interceptor, mock
- Language: TypeScript
- Homepage: https://npmjs.com/connect-web-mock-interceptor
- Size: 43.9 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# connect-web-mock-interceptor
Mock utility for [connect-web](https://github.com/bufbuild/connect-web).
🚧 Streaming requests are not currently supported.
If you want to use with MSW, you can use [msw-connect-web](https://npmjs.com/msw-connect-web).
## Usage
Install package.
```sh
npm i -D connect-web-mock-interceptor @bufbuild/protobuf
```Define mocks.
_handlers.ts_
```typescript
import { createConnectTransport } from '@bufbuild/connect-web';
import { mock } from 'connect-web-mock-interceptor';
const transport = createConnectTransport({
// ...
interceptors: process.env.USE_MOCKS !== 'true' ? [] : [
mock(YourService, "methodName", (req: RequestMessage) => {
// ...
return new ResponseMessage({ /* ... */ });
}),
]
});
```