Skip to content

Commit

Permalink
fix(http): isElementStruct with null
Browse files Browse the repository at this point in the history
  • Loading branch information
marcj committed Feb 11, 2025
1 parent 1e021cf commit 04e54b0
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
15 changes: 12 additions & 3 deletions packages/http/src/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,16 @@
* You should have received a copy of the MIT License along with this program.
*/

import { asyncOperation, ClassType, CustomError, getClassName, getClassTypeFromInstance, isArray, isClassInstance } from '@deepkit/core';
import {
asyncOperation,
ClassType,
CustomError,
getClassName,
getClassTypeFromInstance,
isArray,
isClassInstance,
isObject,
} from '@deepkit/core';
import { OutgoingHttpHeaders, ServerResponse } from 'http';
import { eventDispatcher } from '@deepkit/event';
import { HttpRequest, HttpRequestPositionedParameters, HttpResponse } from './model.js';
Expand All @@ -29,12 +38,12 @@ import {
Type,
typeSettings,
UnpopulatedCheck,
ValidationError
ValidationError,
} from '@deepkit/type';
import stream from 'stream';

export function isElementStruct(v: any): v is ElementStruct {
return 'object' === typeof v && v.hasOwnProperty('render') && v.hasOwnProperty('attributes') && !v.slice;
return isObject(v) && 'hasOwnProperty' in v && v.hasOwnProperty('render') && v.hasOwnProperty('attributes');
}

let templateRender: typeof render;
Expand Down
15 changes: 15 additions & 0 deletions packages/http/tests/core.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { isElementStruct } from '../src/http.js';
import { expect, test } from '@jest/globals';

test('isElementStruct', () => {
expect(isElementStruct(null)).toBe(false);
expect(isElementStruct(undefined)).toBe(false);
expect(isElementStruct(0)).toBe(false);
expect(isElementStruct({})).toBe(false);
expect(isElementStruct(new Date)).toBe(false);
expect(isElementStruct(Object.create(null))).toBe(false);
expect(isElementStruct(true)).toBe(false);
expect(isElementStruct([])).toBe(false);
expect(isElementStruct(function b(){} )).toBe(false);
expect(isElementStruct({render: {}, attributes: {}})).toBe(true);
});

0 comments on commit 04e54b0

Please sign in to comment.