Skip to content

Commit

Permalink
make model loading test compatible with async loading
Browse files Browse the repository at this point in the history
  • Loading branch information
sly7-7 committed Mar 5, 2021
1 parent e770069 commit c4b4d3b
Showing 1 changed file with 19 additions and 15 deletions.
34 changes: 19 additions & 15 deletions packages/ember/tests/routing/model_loading_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { Route } from '@ember/-internals/routing';
import Controller from '@ember/controller';
import { RSVP, Object as EmberObject, A as emberA } from '@ember/-internals/runtime';
import { moduleFor, ApplicationTestCase, getTextOf } from 'internal-test-helpers';
import { moduleFor, ApplicationTestCase, getTextOf, runLoopSettled } from 'internal-test-helpers';
import { run } from '@ember/runloop';
import { computed, set } from '@ember/-internals/metal';
import { isDestroying } from '@glimmer/runtime';
Expand Down Expand Up @@ -754,7 +754,7 @@ class LoadingTests extends ApplicationTestCase {
});
}

['@test Parent route context change'](assert) {
async ['@test Parent route context change'](assert) {
let editCount = 0;
let editedPostIds = emberA();

Expand All @@ -776,8 +776,8 @@ class LoadingTests extends ApplicationTestCase {
'route:posts',
Route.extend({
actions: {
showPost(context) {
expectDeprecation(() => {
async showPost(context) {
await expectDeprecationAsync(() => {
this.transitionTo('post', context);
}, /Calling transitionTo on a route is deprecated/);
},
Expand All @@ -797,8 +797,8 @@ class LoadingTests extends ApplicationTestCase {
},

actions: {
editPost() {
expectDeprecation(() => {
async editPost() {
await expectDeprecationAsync(() => {
this.transitionTo('post.edit');
}, /Calling transitionTo on a route is deprecated/);
},
Expand All @@ -814,22 +814,26 @@ class LoadingTests extends ApplicationTestCase {
editedPostIds.push(postId);
return null;
},

setup() {
this._super(...arguments);
editCount++;
},
})
);

return this.visit('/posts/1').then(() => {
assert.ok(true, '/posts/1 has been handled');
let router = this.applicationInstance.lookup('router:main');
run(() => router.send('editPost'));
run(() => router.send('showPost', { id: '2' }));
run(() => router.send('editPost'));
assert.equal(editCount, 2, 'set up the edit route twice without failure');
assert.deepEqual(editedPostIds, ['1', '2'], 'modelFor posts.post returns the right context');
});
await this.visit('/posts/1');
assert.ok(true, '/posts/1 has been handled');
let router = this.applicationInstance.lookup('router:main');
run(() => router.send('editPost'));
await runLoopSettled();
await runLoopSettled();
run(() => router.send('showPost', { id: '2' }));
await runLoopSettled();
run(() => router.send('editPost'));
await runLoopSettled();
assert.equal(editCount, 2, 'set up the edit route twice without failure');
assert.deepEqual(editedPostIds, ['1', '2'], 'modelFor posts.post returns the right context');
}

['@test ApplicationRoute with model does not proxy the currentPath'](assert) {
Expand Down

0 comments on commit c4b4d3b

Please sign in to comment.