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

[Bug]: toStrictEqual doesn't work on simple arrays returned by C++ addon with node-api #12814

Closed
CMCDragonkai opened this issue May 6, 2022 · 8 comments

Comments

@CMCDragonkai
Copy link

Version

27.3.1

Steps to reproduce

Clone MatrixAI/TypeScript-Demo-Lib#38. Run nix-shell to enter into the development environment.

Go to src/native/index.cpp.

NAPI_METHOD(createArr) {
  // Create arr with length of 1
  napi_value arr;
  NAPI_STATUS_THROWS(napi_create_array_with_length(env, 1, &arr))
  // Set the value on the arr
  napi_value value;
  NAPI_STATUS_THROWS(napi_create_double(env, 0.5, &value));
  NAPI_STATUS_THROWS(napi_set_element(env, arr, 0, value))
  return arr;
}

This native function just creates an JS array, and sets 5 to it. Basically [5].

Now in jest, go to tests/native.test.ts.

Test this:

    expect(native.createArr()).toEqual([0.5]);

Expected behavior

I would expect [0.5] to be [0.5].

Actual behavior

It says: Received: serializes to the same string.

In fact, you can test it like:

    const arr = native.createArr();
    expect(arr[0]).toStrictEqual(0.5);

And this does work.

Additional context

No response

Environment

System:
    OS: Linux 5.10 Matrix ML 1
    CPU: (16) x64 AMD Ryzen 7 2700X Eight-Core Processor
  Binaries:
    Node: 16.14.2 - /nix/store/zl4bvsqfxyx5vn9bbhnrmbmpfvzqj4gd-nodejs-16.14.2/bin/node
    npm: 8.5.0 - /nix/store/zl4bvsqfxyx5vn9bbhnrmbmpfvzqj4gd-nodejs-16.14.2/bin/npm
  npmPackages:
    jest: ^27.2.5 => 27.3.1
@CMCDragonkai
Copy link
Author

CMCDragonkai commented May 6, 2022

Actually this also applies to objects too. And I tested that this also occurs with node's assert.deepStrictEqual. So there must be some difference between objects created inside C++ vs objects created in JS-land.

@CMCDragonkai
Copy link
Author

This applies to node Buffer as well.

@github-actions
Copy link

github-actions bot commented Jul 2, 2022

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 30 days.

@github-actions github-actions bot added the Stale label Jul 2, 2022
@github-actions github-actions bot removed the Stale label Jul 15, 2022
@github-actions
Copy link

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 30 days.

@github-actions github-actions bot added the Stale label Aug 14, 2022
@github-actions
Copy link

This issue was closed because it has been stalled for 7 days with no activity. Please open a new issue if the issue is still relevant, linking to this one.

@github-actions
Copy link

This issue was closed because it has been stalled for 7 days with no activity. Please open a new issue if the issue is still relevant, linking to this one.

@CMCDragonkai
Copy link
Author

This isn't completed nor done... it's a bug.

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 15, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant