fetch-vcr
fetch-vcr copied to clipboard
Multiple cassettes for the same endpoint
Hi,
I am wondering if there is a clean way to have multiple cassettes for the same endpoint and specify which one to use in a test case.
This would be useful when an endpoint might return different JSON body.
My current solution This seams a bit a hacky to me, but it works. I have created a folder architecture and each folder can record a different response for the same endpoint.
test('#saveCurrentUser authorized', async ()=> {
fetch.configure({
fixturePath: './_fixtures/authorized/'
});
// doing fetch to the endpoint example.com/api/test
// this returns {"id":"e4130aaa-f5c","cip":"ciei200","enabled":true}
...
test('#saveCurrentUser unauthorized', async () => {
fetch.configure({
fixturePath: './_fixtures/unauthorized/'
});
// doing fetch to the same endpoint example.com/api/test
// this returns {"error":"invalid_token","error_description":"Invalid access token: 55e854e7b1b"}
Very good work on this lib ! It is very awesome.
Would be nice to handle these the way Jest snapshots work and colocate them: cassetteName: "foo"
. Will try and spin up a PR with this