Niedzielski has uploaded a new change for review. ( 
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, 22 insertions(+), 35 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/marvin refs/changes/57/395657/1

diff --git a/src/common/router/router.test.ts b/src/common/router/router.test.ts
index 58a1f1e..32bd13e 100644
--- a/src/common/router/router.test.ts
+++ b/src/common/router/router.test.ts
@@ -7,71 +7,58 @@
 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 page: 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
         }
       };
 
-      const getPage = (name: string) =>
-        name === "redirect"
-          ? Promise.resolve(page)
+      const resolver = (page: string) =>
+        page === "redirect"
+          ? 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, getPage)
+      return newRouter(routes, resolver)
         .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: newchange
Gerrit-Change-Id: Ia59e7dd59ce302346d551c955d382b1907e1dcee
Gerrit-PatchSet: 1
Gerrit-Project: marvin
Gerrit-Branch: master
Gerrit-Owner: Niedzielski <[email protected]>
Gerrit-Reviewer: Sniedzielski <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to