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]: instanceof Date fails when using a date created from node-api (n-api) #15169

Closed
universalmind303 opened this issue Jul 8, 2024 · 4 comments

Comments

@universalmind303
Copy link

universalmind303 commented Jul 8, 2024

Version

29.7.0

Steps to reproduce

  • create a simple example using napi-rs
  • Note: you will need a valid rust toolchain and configuration for this.
  • npx @napi-rs/cli new
  • cd example
  • update src/lib.rs with a date creating function
  • #![deny(clippy::all)]
    
    use std::time::Instant;
    
    use napi::{Env, JsDate, JsObject, NapiValue};
    
    #[macro_use]
    extern crate napi_derive;
    
    #[napi]
    pub fn create_date(env: Env) -> JsDate {
      let raw_env = env.raw();
      let mut ptr = std::ptr::null_mut();
      let dt = 1011208800000.0;
    
      unsafe {
        napi::sys::napi_create_date(raw_env, dt, &mut ptr);
        JsDate::from_raw(raw_env, ptr).unwrap()
      }
    }
  • build: yarn napi build
  • add jest as dependency: yarn add jest
  • create example test
    • // example.test.ts
      const native = require("./test.node");
      test("toRecords:date", () => {
          const date = native.createDate();
      	    expect(date).toBeInstanceOf(Date);
      });
  • run test: yarn jest example.test.ts

Expected behavior

I expect expect(date).toBeInstanceOf(Date) to be true.

Actual behavior

it is not true

Additional context

running it outside of jest works fine. Originally reported here, but was determined to be a bug within jest

Environment

System: Darwin 23.4.0 arm64 arm
Node: v22.1.0
Yarn: 4.3.1
NPM: 10.7.0
Copy link

github-actions bot commented Aug 7, 2024

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 7, 2024
@universalmind303
Copy link
Author

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.

this is still a valid issue that I don't think should be closed

@github-actions github-actions bot removed the Stale label Aug 7, 2024
@SimenB
Copy link
Member

SimenB commented Aug 8, 2024

Duplicate of #2549

@SimenB SimenB marked this as a duplicate of #2549 Aug 8, 2024
@SimenB SimenB closed this as not planned Won't fix, can't repro, duplicate, stale Aug 8, 2024
Copy link

github-actions bot commented Sep 8, 2024

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 Sep 8, 2024
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

2 participants