Skip to content

Commit

Permalink
fix(cloudformation-diff): format test
Browse files Browse the repository at this point in the history
- Currently, `yarn build` fails in '@aws-cdk-testing' package with following error because 'Received' string is formatted with `chalk.red` and 'Expected' string is by default formatted with `chalk.green`:

```
   ✖  @aws-cdk/cloudformation-diff:test
$ cdk-test
       FAIL  test/format.test.ts
        ● format value can handle partial json strings

          expect(received).toEqual(expected) // deep equality

          Expected: "{\"nice\":\"great\",\"partialJson\":\"{\\\"wow\\\": \\\"great\"}"
          Received: "{\"nice\":\"great\",\"partialJson\":\"{\\\"wow\\\": \\\"great\"}"

            6 | test('format value can handle partial json strings', () => {
            7 |   const output = formatter.formatValue({ nice: 'great', partialJson: '{"wow": "great' }, chalk.red);
          > 8 |   expect(output).toEqual('{\"nice\":\"great\",\"partialJson\":\"{\\\"wow\\\": \\\"great\"}');
              |                  ^
            9 | });

            at Object.<anonymous> (test/format.test.ts:8:18)
```

- But as unit-test aims to test equality of strings in terms of content instead of color formatting, hence, it is better to utilise `toMatch` instead of `toEqual`.
- Upon retesting, unit-test passed:

```
 ✔  @aws-cdk/cloudformation-diff:build  [local cache]
```
  • Loading branch information
Chakshu Gupta authored and ChakshuGupta13 committed Jun 12, 2024
1 parent db3e77d commit 7448549
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion packages/@aws-cdk/cloudformation-diff/test/format.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ const formatter = new Formatter(process.stdout, {});

test('format value can handle partial json strings', () => {
const output = formatter.formatValue({ nice: 'great', partialJson: '{"wow": "great' }, chalk.red);
expect(output).toEqual('{\"nice\":\"great\",\"partialJson\":\"{\\\"wow\\\": \\\"great\"}');
expect(output).toMatch('{\"nice\":\"great\",\"partialJson\":\"{\\\"wow\\\": \\\"great\"}');
});

0 comments on commit 7448549

Please sign in to comment.