Skip to content

Commit

Permalink
test(context): import from correct path, add request properties, and …
Browse files Browse the repository at this point in the history
…fix property existence assertions
  • Loading branch information
m-mdy-m committed Aug 15, 2024
1 parent 02af3a6 commit 4931f27
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions test/core/ctx.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import http, { Server } from 'http';
import { WebContext } from '../../lib/core/ctx/index';
import { WebContext } from '../../lib/core/context/index';
import { assert } from 'chai';
import { describe, it, beforeEach } from 'mocha';
import { PassThrough } from 'stream';
import { Socket } from 'net';

describe('WebContext', () => {
let server: Server, ctx: WebContext;
Expand All @@ -12,6 +13,13 @@ describe('WebContext', () => {
request = new PassThrough() as any;
response = new PassThrough() as any;

// Mock the necessary properties for IncomingMessage
request.url = '/test-url';
request.method = 'GET';
request.headers = {
host: 'localhost:3000',
};
request.socket = new Socket();
// Simulate a real HTTP request/response pair
server = http.createServer((req, res) => {
ctx = new WebContext(req, res);
Expand All @@ -37,8 +45,8 @@ describe('WebContext', () => {
});

it('should check if a property exists on the request or response object', () => {
assert.isFalse('method' in ctx.ctx);
assert.isFalse('statusCode' in ctx.ctx);
assert.isTrue('method' in ctx.ctx);
assert.isTrue('statusCode' in ctx.ctx);
assert.isFalse('nonexistentProp' in ctx.ctx);
});

Expand Down

0 comments on commit 4931f27

Please sign in to comment.