Put query data into the data parameter of the fixture function.#79
Put query data into the data parameter of the fixture function.#79mtnt wants to merge 3 commits intoBedrockStreaming:masterfrom mtnt:get-data
Conversation
|
I think if look through |
|
@elisherer there is. It's in the NB: I removed accidentally added commit |
| return data; | ||
| } | ||
|
|
||
| const parts = url.split('?'); |
There was a problem hiding this comment.
wouldn't it be simpler to check includes?
src/superagent-mock.js
Outdated
| @@ -1,3 +1,6 @@ | |||
| import qs from 'qs'; | |||
| import {isEmpty, isNil} from 'lodash'; | |||
There was a problem hiding this comment.
I think lodash is a big dependency here, will require consumers to have some lind of lodash optimization. better make those checks part of the code or change the imports to direct ones.
There was a problem hiding this comment.
I really think there are totally all projects have lodash) But ok, I removed it)
|
@elisherer could you already merge or reject it?) |
|
Hi, thanks for your contribution @mtnt. I wouldn't be exclusive between post data and query string because it is possible to have query params in a POST url 😄. If I well understand what you need, you can use Regexp capturing groups in the pattern. // Example 1, the pattern is stricted and the query params order is known
{
pattern: 'https://domain.example?limit=(\d+)&offset=(\d+)',
fixtures: match => {
const [, limit, offset] = match;
// ...
}
}
// Example 2, the pattern matches every requests with query params
[{
pattern: 'https://domain.example?(.*)',
fixtures: match => {
const { limit, offset } = qs(match[1]);
// ...
// may handle 404 somewhere
}
}] |
|
@DevSide hmm, I got your point... Yeah, I did not think about usage query params in a POST... Maybe the data should be an object with PS yeah, the regexp is that what I currently use for this purpose. |
|
Usage of a regexp is not convenient: actual params order may be different with a pattern. Much more useful way is to get somehow a package of parsed data. UPD: it`s possible to use "?(.*)" and parse it - in this case each user should reverse engineer the |
|
path-to-regex could be better choice I guess but not sure it handles query params. |
|
Oh, I`m sorry, I forgot one more thing: passing complex params such as objects and arrays are converted not like json: |
No description provided.