-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Custom Jest matchers not working with Typescript #180
Comments
same here :( |
Try this: import * as matchers from 'aws-sdk-client-mock-jest';
describe("blubb", () => {
expect.extend(matchers);
}); Be happy. |
The import modifies the global types which are only available when you install |
It would be awesome if it worked without using |
A work around is to redeclare the matcher functions. ie. copy those in use from https://github.com/m-radzikowski/aws-sdk-client-mock/blob/v3.0.0/packages/aws-sdk-client-mock-jest/src/jestMatchers.ts#L7-L70 import { describe, it, expect, beforeEach } from '@jest/globals';
import { PutObjectAclCommand, S3Client } from '@aws-sdk/client-s3';
- import { mockClient } from 'aws-sdk-client-mock';
+ import { MetadataBearer } from '@smithy/types'
+ import { AwsCommand, mockClient } from 'aws-sdk-client-mock';
import 'aws-sdk-client-mock-jest';
+ declare module 'expect' {
+ interface Matchers<R> {
+ toHaveReceivedCommand<TCmdInput extends object, TCmdOutput extends MetadataBearer>
+ (command: new (input: TCmdInput) => AwsCommand<TCmdInput, TCmdOutput>): R;
+ }
+ }
describe('example', () => {
const s3Mock = mockClient(S3Client);
beforeEach(() => {
s3Mock.reset();
});
it('test', async () => {
expect(s3Mock).toHaveReceivedCommand(PutObjectAclCommand);
});
}); |
They solved this with testing-library in definitely typed like this: DefinitelyTyped/DefinitelyTyped#65981 I fixed in a similar way by adding to
It would be nice if that was just in the package, though. EDIT: this seemed to have fixed the problem but apparently it was just VSCode fooling me. I expect something like this would work, though. |
Jest now includes own types in @jest/globals packages. Use it for custom Jest matchers types. Add declaration exposing custom matchers in the "expect" library types. Fixes #180
Jest now includes own types in @jest/globals packages. Use it for custom Jest matchers types. Add declaration exposing custom matchers in the "expect" library types. Fixes #180
I've migrated to using Released in |
Hey @m-radzikowski, thanks for attempting to fix this, but it's still not working for me, neither for import {
DescribeDBEngineVersionsCommand,
RDSClient,
} from "@aws-sdk/client-rds";
import { beforeEach, expect, it } from "@jest/globals";
import { mockClient } from "aws-sdk-client-mock";
import "aws-sdk-client-mock-jest";
const rdsMock = mockClient(RDSClient);
beforeEach(() => {
rdsMock.reset();
});
it("demo", async () => {
expect(rdsMock).toHaveReceivedCommand(DescribeDBEngineVersionsCommand);
});
"devDependencies": {
"@jest/globals": "^29.7.0",
"@types/node": "^20.11.24",
"aws-sdk-client-mock": "3.1.0-beta.1",
"aws-sdk-client-mock-jest": "^3.0.1",
"esbuild": "^0.20.1",
"esbuild-jest": "^0.5.0",
"jest": "^29.7.0",
"typescript": "^5.3.3"
},
"dependencies": {
"@aws-sdk/client-rds": "^3.525.0"
} I get the following type error:
I've also tried to |
@nmussy you need to update |
That was my issue, thanks 👍 "devDependencies": {
"@jest/globals": "^29.7.0",
"@types/node": "^20.11.24",
"aws-sdk-client-mock": "3.1.0-beta.1",
"aws-sdk-client-mock-jest": "3.1.0-beta.1",
"esbuild": "^0.20.1",
"esbuild-jest": "^0.5.0",
"jest": "^29.7.0",
"typescript": "^5.3.3"
},
"dependencies": {
"@aws-sdk/client-rds": "^3.525.0"
} |
3.1.0-beta.1 in both packages worked for me too. Thanks! |
Checklist
Bug description
The custom Jest matchers don't seem to be properly supported with Typescript. I'm getting the following error when trying to use
toHaveReceivedCommand
. Note that I'm usingimport 'aws-sdk-client-mock-jest'
as per the documentation.Property 'toHaveReceivedCommand' does not exist on type 'Matchers<void, AwsStub<ServiceInputTypes, ServiceOutputTypes, S3ClientResolvedConfig>> & SnapshotMatchers<...> & Inverse<...> & PromiseMatchers<...>'
When I
@ts-ignore
the line the matcher works fine, so it seems like a typing issue? (for theexpect
call?). Is there any additional configuration required to get the matchers set up for Typescript?Reproduction
Environment
The text was updated successfully, but these errors were encountered: