didRequest
See original GitHub issueOccasionally I want to make assertions about what requests are made during a test without changing the behaviour of an existing mocked endpoint. To accomplish this I’ve implemented and am using a method didRequest
.
The didRequest method is called after mirage has intercepted and handled the request. It allows you to make assertions about a request without replacing an existing mirage request handler. For example if you have already defined a mirage request handler
this.server.get('http://example.org/users', function(schema, request) {
return schema.users.all();
});
You can make assertions about the request
this.server.didRequest('GET', 'http://example.org/users', function(request) {
assert.step('get users called');
});
You don’t need to replace the existing request handler with another similar one plus the assertion.
this.server.get('http://example.org/users', function(schema, request) {
assert.step('get users called');
return schema.users.all();
});
I’d like to submit a PR for this but before writing it I’d like to know if there would be any interest in merging it? Is it within scope of functionality mirage-js should provide?
Issue Analytics
- State:
- Created a year ago
- Comments:6
Top GitHub Comments
Thanks, have set it up in large mirage project and working through migration issues.
The split is actually complete. Just Pretender is still part of MirageJS so if you use MSW you will still have pretender in the code until we do a PR to remove it. At that point it will be a breaking change. You will have to say use Pretender. Which means adding mirage-pretender to your package.json. You can do that now and it will use the mirage-pretender version of pretender instead of the pretender included in mirageJS
That means that if you can add mirage-msw to your package.json and do
You can use MSW today. If you do would love to hear any feedback. The
onMockResponse
should be handled, but in a pretendery sort of way to make it backward compatible.For this discussion the arrays for tracking requests are accessible via the pretender instance. You can access that in
server.pretender
in the response code. I dont know if MSW does anything like that, but if you are using MSW there will be aserver.msw
prop to access it. Those arrays should be getters on the interface to abstract away accessing them. However the data in the arrays will be different formats so abstract that as well? Not sure where to draw the line.Interested in any thoughts and PRs on the interfaces.