Instead of creating a new duplicate topic, decide to revive this one.
I cannot catch a loading state in my component integration test. waitFor and waitUntil are called after the timeout finishes while I expect to get them called immediately on component render before the timed-out promise resolves.
I have Monday brain right now so take this with a healthy dose of skepticism but I think you may not want to await render because I think that will wait for the initial render and anything trigged by it (e.g. loadBranches) to settle before moving on.
Indeed, dropping await solved the issue. As I figured, in my case the await was waiting for data load to be finished, which in my component design was triggered on an initial component render. Although I had to add two other tweaks (thanks to replies in Discord forum topic):
void render( due to aggressive lint settings about forcing awaits on promises, and
adding the line below await renderSettled();
The resulting test:
import { render, settled } from '@ember/test-helpers';
import { renderSettled } from '@ember/renderer';
...
test('it renders', async function (assert) {
class StubGithubService extends Service {
getRepoBranches() {
return new Promise((resolve) => {
resolve(
new Response(
JSON.stringify([
{ name: 'main' },
{ name: 'dev' },
{ name: 'feature' },
]),
{
status: 200,
headers: { 'Content-Type': 'application/json' },
},
),
);
});
}
}
this.owner.register('service:github', StubGithubService);
const repo: Repository = {
name: 'ember',
url: 'https://api.github.com/repos/emberjs/ember.js',
};
void render(
<template><BranchRow @selectedRepo="ember" @repo={{repo}} /></template>,
);
await renderSettled();
assert
.dom('[data-test-branches-row="ember"]')
.hasText(
'⏳ Loading...',
'should show loading copy on initial render before data is loaded',
);
await settled();
assert
.dom('[data-test-branches-row="ember"]')
.hasText(
'3 Branches main dev feature',
'should show branches list once data is loaded',
);
});