jenkins-bot has submitted this change and it was merged. (
https://gerrit.wikimedia.org/r/395657 )
Change subject: Chore: update router test style to return Promises
......................................................................
Chore: update router test style to return Promises
• Return Promises to Mocha instead of manually calling `done()`.
• Replace calls to `assert.equal()` with `assert.deepEqual()`. These
aren't needed but seems like a better default.
Change-Id: Ia59e7dd59ce302346d551c955d382b1907e1dcee
---
M src/common/router/router.test.ts
1 file changed, 19 insertions(+), 32 deletions(-)
Approvals:
Jhernandez: Looks good to me, approved
jenkins-bot: Verified
diff --git a/src/common/router/router.test.ts b/src/common/router/router.test.ts
index b301a69..080384a 100644
--- a/src/common/router/router.test.ts
+++ b/src/common/router/router.test.ts
@@ -7,44 +7,37 @@
import * as HomeModule from "../pages/home";
import { RedirectError } from "../http/fetch";
-import { newRoute, PageModule } from "./route";
+import { newRoute } from "./route";
import { newRouter } from "./router";
-const routes = [
- newRoute({
- path: "/",
- page: "home"
- })
-];
+const routes = [newRoute({ path: "/", page: "home" })];
describe("router()", () => {
describe(".route()", () => {
- it("a known route is resolved", done => {
- newRouter(routes)
+ it("a known route is resolved", () => {
+ return newRouter(routes)
.route("/")
- .then(() => done());
+ .then(rsp => {
+ assert.deepEqual(rsp.status, 200);
+ });
});
- // eslint-disable-next-line max-len
- it("an unknown route resolves with the path and appropriate status", done
=> {
- newRouter(routes)
+ it("an unknown route resolves with the path and appropriate status", () =>
{
+ return newRouter(routes)
.route("/404")
.then(res => {
- assert.equal(res.status, 404);
- assert.equal(res.props.path, "/404");
- done();
+ assert.deepEqual(res.status, 404);
+ assert.deepEqual(res.props.path, "/404");
});
});
// eslint-disable-next-line max-len
- it("throws redirect errors up for handling on the server/client
environment", done => {
+ it("throws redirect errors up for handling on the server/client
environment", () => {
// Page module that throws a redirect
- const module: PageModule<undefined, undefined> = {
+ const module = {
default: {
- getInitialProps() {
- // Trick TS and eslint for tests
- if ((_ => true)()) throw new RedirectError(301, "/redirected-url");
- return Promise.reject("Doesn't matter");
+ getInitialProps(): Promise<never> {
+ throw new RedirectError(301, "/redirected-url");
},
Component: () => null
}
@@ -55,23 +48,17 @@
? Promise.resolve(module)
: Promise.reject(new Error("No page found"));
- const routes = [
- newRoute({
- path: "/redirect",
- page: "redirect"
- })
- ];
+ const routes = [newRoute({ path: "/redirect", page: "redirect" })];
- newRouter(routes, requestPageModule)
+ return newRouter(routes, requestPageModule)
.route("/redirect")
.catch(err => {
assert.ok(
err instanceof RedirectError,
"Error is a redirect error on redirect"
);
- assert.equal(err.status, 301);
- assert.equal(err.url, "/redirected-url");
- done();
+ assert.deepEqual(err.status, 301);
+ assert.deepEqual(err.url, "/redirected-url");
});
});
});
--
To view, visit https://gerrit.wikimedia.org/r/395657
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ia59e7dd59ce302346d551c955d382b1907e1dcee
Gerrit-PatchSet: 5
Gerrit-Project: marvin
Gerrit-Branch: master
Gerrit-Owner: Niedzielski <[email protected]>
Gerrit-Reviewer: Jhernandez <[email protected]>
Gerrit-Reviewer: Sniedzielski <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits