Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

msw-inspector

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

msw-inspector - npm Package Compare versions

Comparing version 0.0.1 to 0.1.0

8

dist/index.d.ts

@@ -1,2 +0,2 @@

import type { SetupWorkerApi } from 'msw';
import type { MockedRequest, SetupWorkerApi } from 'msw';
import type { SetupServerApi } from 'msw/node';

@@ -6,5 +6,9 @@ /**

*/
declare function createMSWInspector<FunctionMock extends Function>({ mockSetup, mockFactory, }: {
declare function createMSWInspector<FunctionMock extends Function>({ mockSetup, mockFactory, requestMapper, }: {
mockSetup: SetupServerApi | SetupWorkerApi;
mockFactory: () => FunctionMock;
requestMapper?: (req: MockedRequest) => {
key: string;
record: Record<string, any>;
};
}): {

@@ -11,0 +15,0 @@ /**

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.createMSWInspector = void 0;
function requestMapper(req) {
function defaultRequestMapper(req) {
const { method, headers, body } = req;

@@ -25,3 +25,3 @@ const { protocol, host, pathname, searchParams } = req.url;

*/
function createMSWInspector({ mockSetup, mockFactory, }) {
function createMSWInspector({ mockSetup, mockFactory, requestMapper = defaultRequestMapper, }) {
// Store network requests by url

@@ -28,0 +28,0 @@ const requestLog = new Map();

{
"name": "msw-inspector",
"version": "0.0.1",
"version": "0.1.0",
"description": "Inspect requests intercepted by MSW",

@@ -73,7 +73,7 @@ "main": "dist/index.js",

"**/*.{js,json}": [
"prettier",
"npm t"
"npm run prettier",
"npm run test:source"
],
"**/*.md": [
"prettier"
"npm run prettier"
]

@@ -80,0 +80,0 @@ },

@@ -84,8 +84,30 @@ # MSW inspector

mockFactory, // Function returning a mocked function instance to be inspected in your tests
requestMapper, // Optional mapper function to customize how requests are stored
});
```
#### Options object
`createMSWInspector` accepts the following options object:
```ts
{
mockSetup: SetupServerApi | SetupWorkerApi;
mockFactory: () => FunctionMock;
requestMapper?: (req: MockedRequest) => {
key: string;
record: Record<string, any>;
};
}
```
| Option | Description | Default value |
| ---------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------- |
| **mockSetup** _(required)_ | The instance of `msw` mocks expected to inspect _([`setupWorker`][msw-docs-setup-worker] or [`setupServer`][msw-docs-setup-server] result)_ | - |
| **mockFactory** _(required)_ | A function returning the function mock preferred by your testing framework: It can be `() => jest.fn()` for Jest, `() => sinon.spy()` for Sinon, `() => vi.fn()` for Vitest, etc... | - |
| **requestMapper** | Customize default request's key and record mapping with your own logic. | See [`defaultRequestMapper`](src/index.ts#L11) |
### `getRequests`
Returns a mocked function containing all the calls intercepted for the given absolute url:
Returns a mocked function containing all the calls intercepted at the given absolute url (by default):

@@ -96,3 +118,3 @@ ```ts

Each intercepted request calls the matching mocked function with the following payload:
Each intercepted request calls the matching mocked function with the following default payload:

@@ -99,0 +121,0 @@ ```ts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc