cdktf-vitest
🧪 Terraform CDK's assertions for Vitest.
-
Vitest assertions identical to
cdktf
's official Jest assertions. - Works with both global and imported
expect
.
Installation
npm install cdktf-vitest --save-dev
cdktf-vitest
has peer dependencies on both cdktf
and vitest
, so remember to install those too!
Usage
-
Import and call
setupCdktfVitest
in a a setup file:// vitest.setup.ts or similar import { setupCdktfVitest } from 'cdktf-vitest'; setupCdktfVitest();
-
Add
cdktf-vitest
totypes
in yourtsconfig.json
:// tsconfig.json { "compilerOptions": { "types": ["cdktf-vitest"] } }
❗️ If you don't settypes
, you'll need to addimport 'cdktf-vitest'
to the top of each test file. -
Done!
🎉 The assertions should now be available from theexpect
function, like:import { expect } from 'vitest'; expect(stack).toHaveResouce(resource);
The assertions work exactly like Terraform CDK's official assertions for Jest. For information on how to use them, see their documentation on unit testing with Jest.