Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Robert Jackson <me@rwjblue.com>
  • Loading branch information
cafreeman and rwjblue committed Apr 12, 2022
1 parent ad5cd23 commit 9ccfdf6
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 18 deletions.
2 changes: 1 addition & 1 deletion addon-test-support/@ember/test-helpers/rerender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import renderSettled from './-internal/render-settled';
been rendered in the DOM. **THAT** is what `await rerender()` is _perfect_
for.
@public
@returns {Promise<void>} a promise which fulfills when rendering has settled
@returns {Promise<void>} a promise which fulfills when rendering has completed
*/
export default function rerender() {
return renderSettled();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export interface RenderOptions {
Renders the provided template and appends it to the DOM.
@public
@param {CompiledTemplate} templateOrComponent the template to render
@param {Template|Component} templateOrComponent the component (or template) to render
@param {RenderOptions} options options hash containing engine owner ({ owner: engineOwner })
@returns {Promise<void>} resolves when settled
*/
Expand Down Expand Up @@ -125,17 +125,12 @@ export function render(
// Pre 3.24, we just don't support rendering components at all, so we error
// if we find anything that isn't a template.
const isTemplate =
(Object.prototype.hasOwnProperty.call(templateOrComponent, '__id') &&
Object.prototype.hasOwnProperty.call(
templateOrComponent,
'__meta'
)) ||
(Object.prototype.hasOwnProperty.call(templateOrComponent, 'id') &&
Object.prototype.hasOwnProperty.call(templateOrComponent, 'meta'));
('__id' in templateOrComponent && '__meta' in templateOrComponent) ||
('id' in templateOrComponent && 'meta' in templateOrComponent);

if (!isTemplate) {
throw new Error(
'Prior to Ember 3.24, you may only pass templates to `render`.'
`Using \`render\` with something other than a pre-compiled template is not supported until Ember 3.24 (you are on ${Ember.VERSION}).'
);
}
Expand Down
15 changes: 8 additions & 7 deletions tests/integration/rerender-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ module('rerender real-world', function (hooks) {
await teardownContext(this);
});

test('rerender and settled describe different scenarios', async function (assert) {
test('using rerender to test loading states works', async function (assert) {
let waiter = buildWaiter('test:wat');
let token;
let deferredResolve;
Expand Down Expand Up @@ -56,9 +56,10 @@ module('rerender real-world', function (hooks) {
MyComponent
);

const somePerson = new (class {
class Person {
@tracked name = 'Zoey';
})();
}
const somePerson = new Person();

const template = precompileTemplate(
'<MyComponent @name={{somePerson.name}} />',
Expand All @@ -77,7 +78,7 @@ module('rerender real-world', function (hooks) {
const renderPromise = render(component);

// No actual render
assert.equal(this.element.textContent, '', '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 All @@ -91,7 +92,7 @@ module('rerender real-world', function (hooks) {
'initial render'
);

// updated the component's name argument so it'll trigger a rerender
// updated the person's name to trigger a rerender
somePerson.name = 'Tomster';

// Same logic as render before. We hold on to this promise so we can control when to actually
Expand All @@ -109,8 +110,8 @@ 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);
assert.equal(settledState.hasPendingWaiters, true);
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
2 changes: 1 addition & 1 deletion tests/integration/settled-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ module('settled real-world scenarios', function (hooks) {
assert.equal(this.element.textContent, 'async value');
});

test('rerender', async function (assert) {
test('rerender - it basically works', async function (assert) {
this.owner.register('component:x-test-1', TestComponent1);

await render(hbs`{{x-test-1}}`);
Expand Down

0 comments on commit 9ccfdf6

Please sign in to comment.