Skip to content

Commit

Permalink
test if action is AsyncFunction
Browse files Browse the repository at this point in the history
  • Loading branch information
chungweileong94 committed Mar 7, 2024
1 parent 1ec9bdf commit 94d1e3a
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion packages/server-act/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ describe('action', () => {
expectTypeOf(action).toEqualTypeOf<() => Promise<string>>();
expectTypeOf(action).parameter(0).toBeUndefined();
expectTypeOf(action).returns.resolves.toBeString();

expect(action.constructor.name).toBe('AsyncFunction');
await expect(action()).resolves.toBe('bar');
});

Expand All @@ -20,6 +22,8 @@ describe('action', () => {
expectTypeOf(action).toEqualTypeOf<(input: string) => Promise<string>>();
expectTypeOf(action).parameter(0).toBeString();
expectTypeOf(action).returns.resolves.toBeString();

expect(action.constructor.name).toBe('AsyncFunction');
await expect(action('foo')).resolves.toBe('bar');
});

Expand All @@ -29,6 +33,8 @@ describe('action', () => {
expectTypeOf(action).toEqualTypeOf<(input?: string) => Promise<string>>();
expectTypeOf(action).parameter(0).toBeNullable();
expectTypeOf(action).returns.resolves.toBeString();

expect(action.constructor.name).toBe('AsyncFunction');
await expect(action('foo')).resolves.toBe('foo');
await expect(action()).resolves.toBe('bar');
});
Expand All @@ -40,7 +46,7 @@ describe('action', () => {
expectTypeOf(action).parameter(0).toBeString();
expectTypeOf(action).returns.resolves.toBeString();

// eslint-disable-next-line @typescript-eslint/ban-ts-comment
expect(action.constructor.name).toBe('AsyncFunction');
// @ts-ignore
await expect(action(1)).rejects.toThrowError();
});
Expand All @@ -59,6 +65,8 @@ describe('action', () => {

expectTypeOf(action).toEqualTypeOf<() => Promise<string>>();
expectTypeOf(action).returns.resolves.toBeString();

expect(action.constructor.name).toBe('AsyncFunction');
await expect(action()).resolves.toBe('best-bar');
expect(middlewareSpy).toBeCalledTimes(1);
});
Expand All @@ -72,6 +80,8 @@ describe('action', () => {
expectTypeOf(action).toEqualTypeOf<(param: string) => Promise<string>>();
expectTypeOf(action).parameter(0).toBeString();
expectTypeOf(action).returns.resolves.toBeString();

expect(action.constructor.name).toBe('AsyncFunction');
await expect(action('foo')).resolves.toBe('best-foo-bar');
expect(middlewareSpy).toBeCalledTimes(1);
});
Expand All @@ -90,6 +100,8 @@ describe('formAction', () => {
expectTypeOf(action).parameter(1).toHaveProperty('entries');
expectTypeOf(action).returns.resolves.toBeString();

expect(action.constructor.name).toBe('AsyncFunction');

const formData = new FormData();
await expect(action('foo', formData)).resolves.toMatchObject('bar');
});
Expand All @@ -105,6 +117,8 @@ describe('formAction', () => {
expectTypeOf(action).parameter(1).toHaveProperty('entries');
expectTypeOf(action).returns.resolves.toBeString();

expect(action.constructor.name).toBe('AsyncFunction');

const formData = new FormData();
formData.append('foo', 'bar');
await expect(action('foo', formData)).resolves.toMatchObject('bar');
Expand All @@ -127,6 +141,8 @@ describe('formAction', () => {
expectTypeOf(action).parameter(1).toHaveProperty('get');
expectTypeOf(action).parameter(1).toHaveProperty('entries');

expect(action.constructor.name).toBe('AsyncFunction');

const formData = new FormData();
formData.append('bar', 'foo');

Expand Down

0 comments on commit 94d1e3a

Please sign in to comment.