Skip to content
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

Add failing test for native promises that return another transition. #310

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions tests/index.ts
Expand Up @@ -7,3 +7,4 @@ import './transition_intent_test';
import './transition_state_test';
import './unrecognized-url-error_test';
import './utils_test';
import './native-async-test';
101 changes: 101 additions & 0 deletions tests/native-async-test.ts
@@ -0,0 +1,101 @@
import Router, { Route, Transition } from 'router';
import { Dict } from 'router/core';
import { createHandler, TestRouter } from './test_helpers';

QUnit.module('native async', function (hooks) {
let router: LocalRouter;

class LocalRouter extends TestRouter {
routes: Dict<Route> = Object.create(null);
url: string | undefined;

routeDidChange() {}
routeWillChange() {}
didTransition() {}
willTransition() {}

getRoute(name: string) {
if (this.routes[name] === undefined) {
this.routes[name] = createHandler('empty');
}

return this.routes[name];
}

getSerializer(_name: string) {
return undefined;
}

replaceURL(name: string) {
this.updateURL(name);
}

updateURL(newUrl: string) {
this.url = newUrl;
}
}

hooks.beforeEach(() => {
router = new LocalRouter();
});

QUnit.test('beforeModel with returning router.transitionTo', async function (assert) {
assert.expect(3);

router.map(function (match) {
match('/').to('application', function (match) {
match('/').to('index');
match('/about').to('about');
});
});

router.routes = {
index: createHandler('index', {
beforeModel(_params: Dict<unknown>, _transition: Transition) {
assert.step('index beforeModel');

return router.transitionTo('/about');
},
}),

about: createHandler('about', {
setup() {
assert.step('about setup');
},
}),
};

await router.handleURL('/');

assert.equal(router.url, '/about', 'ended on /about');

assert.verifySteps(['index beforeModel', 'about setup']);
});

QUnit.test('async beforeModel with returning router.transitionTo', async function (assert) {
assert.expect(1);

router.map(function (match) {
match('/').to('application', function (match) {
match('/').to('index');
match('/about').to('about');
});
});

router.routes = {
index: createHandler('index', {
async beforeModel(_params: Dict<unknown>, _transition: Transition) {
return router.transitionTo('/about');
},
}),

about: createHandler('about', {
setup: function () {
assert.ok(true, 'setup was entered');
},
}),
};

await router.handleURL('/');
});
});
2 changes: 1 addition & 1 deletion tests/test_helpers.ts
Expand Up @@ -57,7 +57,7 @@ function transitionTo(
path: string | { queryParams: Dict<unknown> },
...context: any[]
) {
let result = router.transitionTo.apply(router, [path, ...context]);
let result = router.transitionTo(path, ...context);
flushBackburner();
return result;
}
Expand Down