Replies: 2 comments
-
|
Thanks for the suggestion. I'm not a fan of bundling creation of a That said, I can see the utility of a more succinct way to create multiple const [github, assets, gitlab] = MockServer.createAll([
'https://api.github.com',
'https://uploads.github.com',
'https://gitlab.com/api/v4'
]);Thoughts? |
Beta Was this translation helpful? Give feedback.
-
|
In that case, I personally don't see You could consider adding something like this idea for userland to the docs for those who might like it: import { MockServer, FetchMocker } from 'mentoss';
export const mockFetch = baseUrls => {
const servers = [baseUrls].flat().map(url => new MockServer(url));
const mocker = new FetchMocker({
servers
});
return [mocker, ...servers];
};
// usage examples:
const [mocker, server] = mockFetch('https://raw.githubusercontent.com');
const [mocker, api, uploads] = mockFetch(['https://api.github.com', 'https://uploads.github.com']);Might just be a bit less repetitive in certain situations. Personally I like it, but I get it's not Mentoss core API, and in general not everyone will like it. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
While the API is fine as it is and the idea is clear from the start that we need separate server and fetch instances, it might still be interesting to look at an even more concise way to instantiate both.
The main idea is to have a single function (or class), let's call it
mockFetchin this example:Multiple servers:
The conciseness is more obvious when we want to mock multiple servers, also see here for minimal implementation and larger diff set:
Alternatively this could be left in userland, perhaps add such an example to Mentoss docs.
WDYT?
Beta Was this translation helpful? Give feedback.
All reactions