Created
May 6, 2024 18:37
-
-
Save davidtweaver/60e8848345a821f940a2010f0f615fc5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/////// Mocking dynamoDB | |
const mockDynamoDbPut = jest.fn(); | |
class DocumentClient { | |
put = mockDynamoDbPut; | |
} | |
jest.mock('aws-sdk', () => ({ | |
DynamoDB: { | |
DocumentClient, | |
}, | |
})); | |
//.. import { module we want to test } from '.';.// | |
mockDynamoDbPut.mockImplementation(() => ({ promise: jest.fn() })); | |
/////// Mocking a function | |
import { upsert } from './upsert-logic'; | |
jest.mock('./upsert-logic'); | |
const mockUpsert = upsert as jest.MockedFunction<typeof upsert>; | |
mockUpsert.mockResolvedValue('foo') | |
/////// Mocking a class | |
import { SomeClass } from './SomeClass'; | |
jest.mock('./SomeClass'); | |
const mockedClass = <jest.Mock<SomeClass>>SomeClass; | |
/////// Mock object | |
import { mocked } from 'jest-mock'; | |
const mockedObject = jest.mocked(someObject); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment