Skip to content

Commit

Permalink
test: fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
negezor committed Mar 2, 2024
1 parent 0a315af commit 73e7cde
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 54 deletions.
15 changes: 9 additions & 6 deletions test/composer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ describe('Composer', (): void => {
await next();
});

// eslint-disable-next-line @typescript-eslint/require-await
composer.use(async (): Promise<never> => {
throw new Error();
});
Expand All @@ -119,7 +120,7 @@ describe('Composer', (): void => {

it('should only accept middleware as functions', (): void => {
try {
// @ts-ignore
// @ts-expect-error cause test
(new Composer()).use(null);

throw new Error('Middleware must be composed of functions');
Expand All @@ -129,10 +130,11 @@ describe('Composer', (): void => {
});

it('composer should be cloned', async (): Promise<void> => {
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
type CloneContext = {
baseValue?: boolean;
value: 'first' | 'second' | 'default';
};
}

const baseComposer = new Composer<CloneContext>();

Expand Down Expand Up @@ -166,17 +168,17 @@ describe('Composer', (): void => {

expect(baseContext).toMatchObject({
baseValue: true,
value: 'default'
value: 'default',
});

expect(firstContext).toMatchObject({
baseValue: true,
value: 'first'
value: 'first',
});

expect(secondContext).toMatchObject({
baseValue: true,
value: 'second'
value: 'second',
});
});

Expand Down Expand Up @@ -229,9 +231,10 @@ describe('Composer', (): void => {

try {
await middleware({}, noopNext);
// @ts-expect-error cause test
} catch ({ message }) {
expect(message).toEqual(
expect.stringMatching('multiple times')
expect.stringMatching('multiple times'),
);

return;
Expand Down
13 changes: 7 additions & 6 deletions test/middleware.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ describe('compose', (): void => {
await delay(1);

out.push(4);
}
},
]);

await middleware(out, noopNext);
Expand All @@ -70,7 +70,7 @@ describe('compose', (): void => {
await next();

expect(ctx).toBe(context);
}
},
]);

await middleware(context, noopNext);
Expand All @@ -92,7 +92,7 @@ describe('compose', (): void => {
},
async (): Promise<never> => {
throw new Error();
}
},
]);

try {
Expand All @@ -108,7 +108,7 @@ describe('compose', (): void => {

it('should only accept middleware as functions', (): void => {
try {
// @ts-ignore
// @ts-expect-error cause test
compose([null]);

throw new Error('Middleware must be composed of functions');
Expand All @@ -128,14 +128,15 @@ describe('compose', (): void => {
},
async (ctx, next): Promise<void> => {
await next();
}
},
]);

try {
await middleware({}, noopNext);
// @ts-expect-error cause error
} catch ({ message }) {
expect(message).toEqual(
expect.stringMatching('multiple times')
expect.stringMatching('multiple times'),
);

return;
Expand Down
Loading

0 comments on commit 73e7cde

Please sign in to comment.