-
-
Notifications
You must be signed in to change notification settings - Fork 259
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Let's add fetch to the settled checks? #1275
Comments
Monkey-patching My own opinion here is that the right move is:
That latter point gets at why I think patching If, in your app, you want a wrapped import { waitForPromise } from '@ember/test-waiters';
export function fetch(...fetchArgs) {
return waitForPromise(window.fetch(...fetchArgs));
} What's more, that leaves every app in control of their own handling for this, so that if (as you note in your own example here) you need further customization for your own particular test setup, you can just write that. It also makes it really obvious for someone new to that app where and how this is implemented when they want to understand it. One of the great upsides to imports is they give you breadcrumbs to follow. (Insofar as it's useful to have that exist as a shared behavior, I think there's a reasonable argument that this and only this is what |
That all sounds logical to me. I mostly wanted to shine a light here, because it was not fun having to figure out why all my tests were failing, and then it was very difficult finding an explanation until finally finding that one thread in ember-fetch. And then coming up with this code that could deal with what Pretender was doing was another large hurdle. Though that is largely Pretenders' fault for not having a way to provide a custom fetch. Ultimately there wasn't any kind of "here's what you should do!" kind of answer, anywhere. I hope this github issue here helps others out, because I don't think my setup is anything unusual. |
I've been updating an application to be ember 4 ready, part of that involved setting
jquery-integration: false
- meaning all existingember-ajax
andember-data
calls have switched from ajax to fetch.Everything works great! Except... for our tests. Basically any test that was previously doing some kind of ajax request and asserting a result now fails, due to not waiting for the request to finish before asserting.
I have some options;
A) use ember-fetch 🟥
B) use ember-test-waiters in a lot of places 🟥
C) register fetch promises just like ajax requests with the test waiter system 🟢
In theory, an ember app could do something like this before the tests run...
but my setup is more complicated, because I use pretender. This is likely a common setup - pretender is used by both mirage and ember-data-factory-guy. Pretender ignores whatever window.fetch is and assigns it with the github fetch polyfill
https://github.com/pretenderjs/pretender/blob/a6d53af7d5d16c3b68670a00aa2b0706a09b6ae6/src/pretender.ts#L123-L129
So we need something a little more robust that sticks around when assigned - as a proof of concept I put the following together in my test suite, and it works well.
From here though, I have no idea how to integrate this into ember-test-helpers. If someone would like to give some guidance, or wield the torch, that would be great.
Over in ember-fetch, it seems the agreed upon way forward looks is to handle this in ember-test-helpers's
settled()
test helperember-cli/ember-fetch#656 (comment)
The text was updated successfully, but these errors were encountered: