Browse Source

refactor: updates tests and README.md

e22m4u 3 weeks ago
parent
commit
bb17c70736
2 changed files with 15 additions and 15 deletions
  1. 11 10
      README.md
  2. 4 5
      src/route.spec.js

+ 11 - 10
README.md

@@ -101,16 +101,17 @@ router.defineRoute({
   handler(ctx) {
   handler(ctx) {
     // GET /users/10?include=city
     // GET /users/10?include=city
     // Cookie: foo=bar; baz=qux;
     // Cookie: foo=bar; baz=qux;
-    console.log(ctx.req);      // IncomingMessage
-    console.log(ctx.res);      // ServerResponse
-    console.log(ctx.params);   // {id: 10}
-    console.log(ctx.query);    // {include: 'city'}
-    console.log(ctx.headers);  // {cookie: 'foo=bar; baz=qux;'}
-    console.log(ctx.cookies);  // {foo: 'bar', baz: 'qux'}
-    console.log(ctx.method);   // "GET"
-    console.log(ctx.path);     // "/users/10?include=city"
-    console.log(ctx.pathname); // "/users/10"
-    console.log(ctx.meta);     // {prop: 'value'}
+    console.log(ctx.req);       // IncomingMessage
+    console.log(ctx.res);       // ServerResponse
+    console.log(ctx.params);    // {id: 10}
+    console.log(ctx.query);     // {include: 'city'}
+    console.log(ctx.headers);   // {cookie: 'foo=bar; baz=qux;'}
+    console.log(ctx.cookies);   // {foo: 'bar', baz: 'qux'}
+    console.log(ctx.method);    // "GET"
+    console.log(ctx.path);      // "/users/10?include=city"
+    console.log(ctx.pathname);  // "/users/10"
+    console.log(ctx.meta);      // {prop: 'value'}
+    console.log(ctx.container); // ServiceContainer
     // ...
     // ...
   },
   },
 });
 });

+ 4 - 5
src/route.spec.js

@@ -370,14 +370,13 @@ describe('Route', function () {
 
 
   describe('handle', function () {
   describe('handle', function () {
     it('invokes the handler with the given RequestContext and return its result', function () {
     it('invokes the handler with the given RequestContext and return its result', function () {
-      const handler = ctx => {
-        expect(ctx).to.be.instanceof(RequestContext);
-        return 'OK';
-      };
       const route = new Route({
       const route = new Route({
         method: HttpMethod.GET,
         method: HttpMethod.GET,
         path: '/',
         path: '/',
-        handler,
+        handler(ctx) {
+          expect(ctx).to.be.instanceof(RequestContext);
+          return 'OK';
+        },
       });
       });
       const req = createRequestMock();
       const req = createRequestMock();
       const res = createResponseMock();
       const res = createResponseMock();