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

feat(test): implement toEqualIgnoringWhitespace #6293

Merged
merged 2 commits into from
Oct 11, 2023

Conversation

EladBezalel
Copy link
Contributor

@EladBezalel EladBezalel commented Oct 4, 2023

What does this PR do?

  • adds toEqualIgnoringWhitespace to bun test utils
  • adds strings.removeWhitespace to zig strings utils

How did you verify your code works?

  • I ran bun test on expect.test.js & jest-extended.test.js
  • I included a test for the new code
  • I added TypeScript types for the new methods, getters, or setters
  • I ran make codegen to regenerate the C++ and Zig code

related to #1825

const value: JSValue = this.getValue(globalThis, thisValue, "toEqualIgnoringWhitespace", "<green>expected<r>") orelse return .zero;

const not = this.flags.not;
var pass = value.isString() and expected.isString();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does expect({}).not.toEqualIgnoringWhitespace({}) pass in jest extended? We might need to throw an error for unexpected arg types

var valueStr = value.toString(globalThis).toSlice(globalThis, default_allocator).slice();

// Remove all whitespace from both strings
expectedStr = strings.removeWhitespace(default_allocator, expectedStr);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you change this to compare the original strings, skipping all whitespace characters in the comparison? This way we don't need to allocate more memory

@dylan-conway dylan-conway merged commit c2c3b0d into oven-sh:main Oct 11, 2023
@dylan-conway
Copy link
Collaborator

Thank you

@EladBezalel EladBezalel deleted the feat/toEqualIgnoringWhitespace branch October 11, 2023 07:32
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 this pull request may close these issues.

2 participants