Skip to content

Commit

Permalink
chore: extra type tests
Browse files Browse the repository at this point in the history
  • Loading branch information
wmertens committed Dec 13, 2023
1 parent a1c68ec commit a8123e6
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/qwik-city/runtime/src/server-functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ export const serverQrl = <T extends ServerFunction>(qrl: QRL<T>): ServerQRL<T> =
} else {
// Running on the client, we need to call the function via HTTP
const ctxElm = _getContextElement();
const filtered = args.map((arg) => {
const filtered = args.map((arg: unknown) => {
if (arg instanceof SubmitEvent && arg.target instanceof HTMLFormElement) {
return new FormData(arg.target);
} else if (arg instanceof Event) {
Expand Down
32 changes: 32 additions & 0 deletions packages/qwik-city/runtime/src/server-functions.unit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,37 @@ describe('types', () => {

expectTypeOf(callIt).not.toBeAny();
expectTypeOf(callIt).returns.toMatchTypeOf<Promise<RequestEventBase>>();

const serverGetSourceSnippet = server$(async function (
publicApiKey: string,
symbolHash: string
) {
return {
fullName: 'fullName',
count: 5,
origin: 'origin',
originUrl: 'url',
source: 'source',
};
});
expectTypeOf(serverGetSourceSnippet).not.toBeAny();
expectTypeOf(serverGetSourceSnippet('hi', 'there')).toEqualTypeOf<
Promise<{
fullName: string;
count: number;
origin: string;
originUrl: string;
source: string;
}>
>();
expectTypeOf(serverGetSourceSnippet(new AbortController().signal, 'hi', 'there')).toEqualTypeOf<
Promise<{
fullName: string;
count: number;
origin: string;
originUrl: string;
source: string;
}>
>();
});
});
9 changes: 8 additions & 1 deletion packages/qwik/src/core/render/jsx/types/jsx-types.unit.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { assertType, describe, expectTypeOf, test } from 'vitest';
import { $ } from '../../../qrl/qrl.public';
import { $, type PropFunction } from '../../../qrl/qrl.public';
import type { EventHandler, QRLEventHandlerMulti } from './jsx-qwik-attributes';
import type { JSXNode } from './jsx-node';
import type { QwikIntrinsicElements } from './jsx-qwik-elements';
Expand Down Expand Up @@ -38,6 +38,13 @@ describe('types', () => {
EventHandler<PointerEvent, SVGSVGElement> | QRLEventHandlerMulti<PointerEvent, SVGSVGElement>
>();
});
test('PropFunction', () => () => {
const CmpButton = component$<{
onClick$?: PropFunction<() => void>;
}>((props) => <button onClick$={props.onClick$} />);

<CmpButton onClick$={() => alert('CLICKED!')}>click me!</CmpButton>;
});
test('unknown string component', () => () => {
const t = (
<hello-there
Expand Down

0 comments on commit a8123e6

Please sign in to comment.