Skip to content

Commit

Permalink
PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
cafreeman committed Apr 12, 2022
1 parent bdf695f commit 8d935fb
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 7 deletions.
2 changes: 2 additions & 0 deletions addon-test-support/@ember/test-helpers/settled.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,8 @@ export interface SettledState {
- `pendingRequestCount` - The count of pending AJAX requests.
- `debugInfo` - Debug information that's combined with info return from backburner's
getDebugInfo method.
- `isRenderPending` - Checks if there are any pending render operations. This will be true as long
as there are tracked values in the template that have not been rerendered yet.
@public
@returns {Object} object with properties for each of the metrics used to determine settledness
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import type { ComponentInstance } from '@glimmer/interfaces';
const OUTLET_TEMPLATE = hbs`{{outlet}}`;
const EMPTY_TEMPLATE = hbs``;
const INVOKE_PROVIDED_COMPONENT = hbs`<this.ProvidedComponent />`;
const DYNAMIC_INVOKE_PROVIDED_COMPONENT = hbs`{{component this.ProvidedComponent}}`;

export interface RenderingTestContext extends TestContext {
render(template: TemplateFactory): Promise<void>;
Expand Down Expand Up @@ -183,7 +184,7 @@ export function render(
ProvidedComponent: name,
};
ownerToRenderFrom.register(componentFullName, templateOrComponent);
templateOrComponent = hbs`{{component this.ProvidedComponent}}`;
templateOrComponent = DYNAMIC_INVOKE_PROVIDED_COMPONENT;
ownerToRenderFrom.register(templateFullName, templateOrComponent);
}
} else {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"test:all": "ember try:each"
},
"peerDependencies": {
"ember-source": "*"
"ember-source": ">=3.8.0"
},
"dependencies": {
"@ember/test-waiters": "^3.0.0",
Expand Down
23 changes: 20 additions & 3 deletions tests/integration/rerender-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,13 @@ import GlimmerComponent from '@glimmer/component';
import { tracked } from '@glimmer/tracking';
import { hbs } from 'ember-cli-htmlbars';
import { module, test } from 'qunit';
import hasEmberVersion from '@ember/test-helpers/has-ember-version';

module('rerender real-world', function (hooks) {
// this test requires Ember 3.25 in order to use lexically scoped values in templates
if (!hasEmberVersion(3, 25)) {
return;
}
hooks.beforeEach(async function () {
await setupContext(this);
await setupRenderingContext(this);
Expand Down Expand Up @@ -78,7 +83,11 @@ module('rerender real-world', function (hooks) {
const renderPromise = render(component);

// No actual render
assert.equal(this.element.textContent, '', 'precond - Nothing on the screen yet');
assert.equal(
this.element.textContent,
'',
'precond - Nothing on the screen yet'
);

// This lets us wait for rendering to actually occur without resolving the render promise itself.
// This way, we can make assertions about the initial state while also keeping the settled state
Expand Down Expand Up @@ -110,8 +119,16 @@ module('rerender real-world', function (hooks) {
// At this point, we've got both render and rerender suspended, so settled state should reflect
// that there is a render pending AND that the waiter that got kicked off in the component's
// constructor is pending
assert.equal(settledState.isRenderPending, true, 'ensure isRenderPending is true');
assert.equal(settledState.hasPendingWaiters, true, 'ensure test harness / setup is working -- test waiter is pending');
assert.equal(
settledState.isRenderPending,
true,
'ensure isRenderPending is true'
);
assert.equal(
settledState.hasPendingWaiters,
true,
'ensure test harness / setup is working -- test waiter is pending'
);

// This should resolve isRenderPending but not affect the waiters at all since rerender only
// waits on pending render operations. **The point of this whole test is basically to prove that
Expand Down
6 changes: 4 additions & 2 deletions tests/integration/settled-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,12 @@ module('settled real-world scenarios', function (hooks) {
test('rerender - it basically works', async function (assert) {
this.owner.register('component:x-test-1', TestComponent1);

await render(hbs`{{x-test-1}}`);
let renderPromise = render(hbs`{{x-test-1}}`);
await rerender();

assert.equal(this.element.textContent, 'async value');
assert.equal(this.element.textContent, 'initial value');

await renderPromise;
});

test('does not error for various argument types', async function (assert) {
Expand Down

0 comments on commit 8d935fb

Please sign in to comment.