Currently, I am faced with a challenge of writing a test that is expected to fail when trying to instantiate the S3Client object. It seems like Vitest (similar to Jest) replaces the constructor with its own version when mocked, preventing my original constructor from being invoked.
Here is what I have tried:
vi.mock('@aws-sdk/client-s3', async () => {
const module = await vi.importActual<typeof import('@aws-sdk/client-s3')>('@aws-sdk/client-s3')
Object.defineProperty(module.S3Client.prototype, 'constructor', {
value: function () {
throw new Error("Can't construct S3Client")
},
writable: true,
configurable: true,
})
return {
...module,
}
})
Could anyone advise me on how to generate an exception from the constructor in this scenario?