support selecting interceptors #2072
-
ScopeAdds a new behavior Compatibility
Feature descriptionmaybe there's a clear reason but why are there no options when creating the server? seems quite limiting. for example, if i only wanna mock xml request: const server = new SetupServerApi(handlers, {
interceptors: [XMLHttpInterceptor]
} |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Hi, @juliusmarminge. That's a good question! MSW promotes the philosophy that you can describe the network regardless of the implementation details of that network. Providing a precise interceptor is not something we encourage directly because you want consistent behavior no matter how the request is made. If you absolutely must narrow down the interception, you can do that by creating your own import { XMLHttpRequestInterceptor } from '@mswjs/interceptors/XMLHttpRequest'
import { SetupServerCommonApi } from 'msw/node'
class SetupXMLHttpRequestServerApi extends SetupServerCommonApi {
constructor(...handlers) {
super([XMLHttpRequestInterceptor], handlers)
}
}
function mySetupServer(...handlers) {
return new SetupXMLHttpRequestServerApi(...handlers)
} You will be limited in the feature set, however, since |
Beta Was this translation helpful? Give feedback.
Hi, @juliusmarminge. That's a good question!
MSW promotes the philosophy that you can describe the network regardless of the implementation details of that network. Providing a precise interceptor is not something we encourage directly because you want consistent behavior no matter how the request is made.
If you absolutely must narrow down the interception, you can do that by creating your own
setupServer
function using the public API: