Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is format() method in std/testing/asserts.ts working as expected #5590

Closed
RobDWaller opened this issue May 18, 2020 · 1 comment
Closed

Is format() method in std/testing/asserts.ts working as expected #5590

RobDWaller opened this issue May 18, 2020 · 1 comment

Comments

@RobDWaller
Copy link
Contributor

Hi I've been having a look at this and I'm a little unclear what the expected behavior should be for the format() method within std/testing/assets.ts module.

See related issues: #4023 and #4749

If I write a failing test which inputs 'John said, "Hello!" to Dave.' I will get the following output to the command line "John said, \"Hello!\" to Dave." .

As an example, this test:

test({
  name: "failed with string contains quote",
  fn(): void {
    assertThrows(
      (): void => assertEquals(
        'John said, "Hello!" to Dave.',
        'John said, "Hello" to Dave.'
      ),
      AssertionError,
      [
        "Values are not equal:",
        ...createHeader(),
        removed(`-   "John said, "Hello!" to Dave."`),
        added(`+   "John said, "Hello" to Dave."`),
        "",
      ].join("\n")
    );
  },
});

Will produce this output:

deno-fail

Is the replace() method actually required here given the string is inside a template literal?

string = `"${string.replace(/(?=["\\])/g, "\\")}"`;

If it is removed it resolves this issue and does not seem to break any other tests. It would be great to get some clarification on what the expected behavior is as it will influence how tests are written generally.

@RobDWaller
Copy link
Contributor Author

This is expected behaviour, not an issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants