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: Add some jest-extended matchers to bun test #13628

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

nithinkjoy-tech
Copy link
Contributor

What does this PR do?

Add toContainEntry toContainEntries toContainAllEntries toContainAnyEntries from #1825

  • Documentation or TypeScript types (it's okay to leave the rest blank in this case)
  • Code changes

How did you verify your code works?

  • Wrote automated test cases
  • I included a test for the new code
  • I wrote TypeScript/JavaScript tests and they pass locally (bun-debug test jest-extended.test.js)

@nithinkjoy-tech nithinkjoy-tech changed the title Nithin/implement some jest extended matchers Implement some jest extended matchers Aug 30, 2024
@nithinkjoy-tech nithinkjoy-tech changed the title Implement some jest extended matchers feat: Added some jest-extended matchers to bun test Aug 30, 2024
@nithinkjoy-tech nithinkjoy-tech changed the title feat: Added some jest-extended matchers to bun test feat: Add some jest-extended matchers to bun test Aug 30, 2024
@nithinkjoy-tech
Copy link
Contributor Author

@Jarred-Sumner Code updated, ready for review. Thanks

var pass = false;

if (!value.isUndefinedOrNull()) {
const key = expected.getIndex(globalObject, 0);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
const key = expected.getIndex(globalObject, 0);
const key = expected.getIndex(globalObject, 0);
if (globalObject.hasException()) return .zero;

Each getIndex call will need to check for exceptions. It's possible for the array to throw

var obj = { a: 1 };
var arr = ["a"];
Object.defineProperty(arr, 1, {
    get: function() {
        throw new Error("error");
    }
    enumerable: true,
}
expect(obj).toContainEntry(arr);

defer key_string.deref();

const property_value = expected.getIndex(globalObject, 1);
const accessed_property_value = value.getOwn(globalObject, key_string) orelse JSValue.undefined;
Copy link
Member

Choose a reason for hiding this comment

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

I think the orelse case should set pass = false. Currently this test will pass when it should fail:

expect({}).toContainEntry([ a, 1 ]);

Copy link
Member

Choose a reason for hiding this comment

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

Applies similarly to toContainEntries, toContainAllEntries, and toContainAnyEntries

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.

3 participants