Cdktf testing in typescript, how to do multiple expects for a single synthScope

In the example’s I’m only seing a single assertion (expect) for each syntscope. This leads to a LOT of repeated code, as we’d want to make a lot of assertions per Testing.synthScope.

Anyone found a way to do something like

describe('min', function() {
  it('returns the minimum of two numbers', function() {
    var min = require('../ch03');
    expect(min(2, 3)).toBe(2);
    expect(min(22, 3)).toBe(3);
    expect(min(2, -3)).toBe(-3);
  });
});

with the Testing module in cdktf? I can’t get it to work

You can do it by saving you Testing.synthScope result in a function:

function synthMyConcstruct(arg1, arg2) {
  // use the args inside of the callback for synthScope however you like
  return Testing.synthScope(...); 
}

it("does sth", function(){
  expect(synthMyConcstruct(2, 3).toMatchSnapshot();
})
it("does sth else", function(){
  expect(synthMyConcstruct(22, 33).toMatchSnapshot();
})
1 Like

thanks! I will definetely try that.