From 6a6bacfca3bba0c9b1d95efeedbf8dd17f2c79f5 Mon Sep 17 00:00:00 2001 From: tolluset Date: Mon, 3 Apr 2023 00:22:01 +0900 Subject: [PATCH 1/2] chore(docs): change to `synth` from `synthScope` for #2755 --- website/docs/cdktf/test/unit-tests.mdx | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/website/docs/cdktf/test/unit-tests.mdx b/website/docs/cdktf/test/unit-tests.mdx index 89d11ddcc7..ec3523fbf3 100644 --- a/website/docs/cdktf/test/unit-tests.mdx +++ b/website/docs/cdktf/test/unit-tests.mdx @@ -27,9 +27,9 @@ If you would like to add testing to an existing project, refer the following res ### Write Assertions -The following Typescript example uses `Testing.synthScope` to test a part of the application. This creates a scope to test a subset of the application and returns a JSON string representing the synthesized HCL-JSON. Then it uses custom matchers to verify the code acts as intended. +The following Typescript example uses `Testing.synth` to test a part of the application. Given the desired scope to test, a JSON string representing the synthesized HCL-JSON is returned. Then the custom assertions under `Testing` in the cdktf package can be used to verify the code acts as intended. `Testing.synth` can test the `Stack` that extends the `TerraformStack`. -The other examples use `Testing.synth` to test a part of the application. Given the desired scope to test, a JSON string representing the synthesized HCL-JSON is returned. Then the custom assertions under `Testing` in the cdktf package can be used to verify the code acts as intended. +The other examples use `Testing.synthScope` to test a part of the application. This creates a scope to test a subset of the application and returns a JSON string representing the synthesized HCL-JSON. Then it uses custom matchers to verify the code acts as intended. `Testing.synthScope` can test the `Constructs` that extends the `IConstruct`. Examples in @@ -50,19 +50,19 @@ import MyApplicationsAbstraction from "../app"; // Could be a class extending fr describe("Unit testing using assertions", () => { it("should contain a container", () => { - expect( - Testing.synthScope((scope) => { - new MyApplicationsAbstraction(scope, "my-app", {}); - }) - ).toHaveResource(Container); + const app = Testing.app(); + const stack = new MyApplicationsAbstraction(app, "my-app", {}); + const synthesized = Testing.synth(stack); + + expect(synthesized).toHaveResource(Container); }); it("should use an ubuntu image", () => { - expect( - Testing.synthScope((scope) => { - new MyApplicationsAbstraction(scope, "my-app", {}); - }) - ).toHaveResourceWithProperties(Image, { name: "ubuntu:latest" }); + const app = Testing.app(); + const stack = new MyApplicationsAbstraction(app, "my-app", {}); + const synthesized = Testing.synth(stack); + + expect(synthesized).toHaveResourceWithProperties(Image, { name: "ubuntu:latest" }); }); }); ``` From 60264660ec9f915f019e7f04bb55e956297bdaec Mon Sep 17 00:00:00 2001 From: Ansgar Mertens Date: Tue, 18 Apr 2023 12:26:46 +0200 Subject: [PATCH 2/2] fix(docs): run prettier --- website/docs/cdktf/test/unit-tests.mdx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/website/docs/cdktf/test/unit-tests.mdx b/website/docs/cdktf/test/unit-tests.mdx index ec3523fbf3..1f07527cc0 100644 --- a/website/docs/cdktf/test/unit-tests.mdx +++ b/website/docs/cdktf/test/unit-tests.mdx @@ -62,7 +62,9 @@ describe("Unit testing using assertions", () => { const stack = new MyApplicationsAbstraction(app, "my-app", {}); const synthesized = Testing.synth(stack); - expect(synthesized).toHaveResourceWithProperties(Image, { name: "ubuntu:latest" }); + expect(synthesized).toHaveResourceWithProperties(Image, { + name: "ubuntu:latest", + }); }); }); ```