Open samselikoff opened 4 years ago
Not sure whether this is related. I have tried MirageJS on React Native and found that queryParams doesn't work. The route and request look like this:
this.get('/movies?a=:a', ...)
// request
fetch('/movies?a=1')..
and here is the error I have got:
The way pretender works is you access the query params via the request object. Does the route handler fire if you just put this.get(‘movies’)?
– Sam
On Jun 4, 2020, at 2:29 AM, Tulakan Ruangrong notifications@github.com wrote:
Not sure whether this is related. I have tried MirageJS on React Native and found that queryParams doesn't work. The route and request looks like this:
this.get('/movies?a=:a', ...)
// request fetch('/movies?a=1').. and here is the error I have got:
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.
@samselikoff oh my bad, I was confusing on how to write this. Sorry about that and thank you very much!
No prob at all - let me know if you have any more questions!
I've just hit this as well. It seems that the request doesn't have queryParams initially (can observe using console.log(JSON.stringify(request))
, but it does get added eventually, as you can see if you just console.log(request)
.
For now, I am working around this issue using:
const url = new URL(request.url);
const params = new URLSearchParams(url.searchParams);
return params.get('skipMirage') === 'true';
I think that is a decent approach. Maybe the docs could be updated to show that method instead of trying to access request.queryParams
, which fails?
Believe the
request
object we pass topassthrough
when its used as a function doesn't havequeryParams
defined, not sure if this is a Pretender thing or an us thing