If you follow the documentation for Fine-grained Assertions - the test will pass.
It's not a real-world scenario though - you don't create a resource in a test, you create the resource in the stack definition.
If you modify the test and move new dlq.DeadLetterQueue(...) inside of the new Stack() call (assuming new Stack() is a custom stack like export class MyStack extends Stack { ... }, the test will fail and indicate that there are 0 resources.
You can fix this error by adding a line; const stackTemplate = SynthUtils.toCloudFormation(new MyStack()) and passing the stackTemplate variable to the expect(...) call instead of the stack variable.
I'm not sure if this is a bug with the jest matcher though, or whether this fix is the right approach and the documentation just isn't quite matching up to a real-world scenario?
If you follow the documentation for Fine-grained Assertions - the test will pass.
It's not a real-world scenario though - you don't create a resource in a test, you create the resource in the stack definition.
If you modify the test and move
new dlq.DeadLetterQueue(...)inside of thenew Stack()call (assumingnew Stack()is a custom stack likeexport class MyStack extends Stack { ... }, the test will fail and indicate that there are 0 resources.You can fix this error by adding a line;
const stackTemplate = SynthUtils.toCloudFormation(new MyStack())and passing thestackTemplatevariable to theexpect(...)call instead of thestackvariable.I'm not sure if this is a bug with the jest matcher though, or whether this fix is the right approach and the documentation just isn't quite matching up to a real-world scenario?