Skip to content

mock.property(): 'process.env' does not accept an accessor(getter/setter) descriptor #60486

Description

@regseb

Version

v22.21.0

Platform

Linux regseblaptop4l 6.14.0-34-generic #34-Ubuntu SMP PREEMPT_DYNAMIC Wed Sep 17 09:21:29 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux

Subsystem

No response

What steps will reproduce the bug?

  1. Create index.js:
    import { mock } from "node:test";
    
    console.log(Object.getOwnPropertyDescriptor(process.env, "PATH"));
    
    mock.property(process.env, "PATH", "foo");
    
    console.log(process.env.PATH);
  2. node index.js

How often does it reproduce? Is there a required condition?

Always.

What is the expected behavior? Why is that the expected behavior?

The variable process.env.PATH is mocked by mock.property(object, propertyName[, value]).

{
  value: '/usr/local/sbin:/usr/local/bin:/usr/sbin',
  writable: true,
  enumerable: true,
  configurable: true
}
foo

What do you see instead?

{
  value: '/usr/local/sbin:/usr/local/bin:/usr/sbin',
  writable: true,
  enumerable: true,
  configurable: true
}
node:internal/test_runner/mock/mock:308
    ObjectDefineProperty(object, propertyName, {
    ^

TypeError: 'process.env' does not accept an accessor(getter/setter) descriptor
    at defineProperty (<anonymous>)
    at new MockPropertyContext (node:internal/test_runner/mock/mock:308:5)
    at MockTracker.property (node:internal/test_runner/mock/mock:717:7)
    at file:///home/regseb/testcase/index.js:5:6
    at ModuleJob.run (node:internal/modules/esm/module_job:343:25)
    at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:665:26)
    at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:117:5) {
  code: 'ERR_INVALID_OBJECT_DEFINE_PROPERTY'
}

Node.js v22.21.0

Additional information

Pull request for adding the mock.property() method: #58438

Activity

  1. sakina1303 commented on Oct 30, 2025

    @sakina1303

    can i please work on this! kindly assign it to me.

  2. marco-ippolito commented on Oct 30, 2025

    @marco-ippolito
    Member

    can i please work on this! kindly assign it to me.

    you can just send a PR, we usually dont assign issues

  3. sakina1303 commented on Oct 30, 2025

    @sakina1303

    can i please work on this! kindly assign it to me.

    you can just send a PR, we usually dont assign issues

    Got it, thank you! I’ll start working on it and raise a PR once it’s ready.

  4. sakina1303 commented on Oct 30, 2025

    @sakina1303

    @marco-ippolito Kindly review the PR when you get a chance. Thank you!

  5. Renegade334 commented on Nov 1, 2025

    @Renegade334
    Member

    Note that this was a deliberate design decision made in #28006. If the motivation for that change still stands, then this is WONTFIX.

    The question is whether an accessor property could be considered consistent with the behaviour of conventional process.env properties, if it's a getter/setter pair and is configurable and enumerable. Obviously there's no guarantee that the user-provided accessor will behave as expected.

    (cc: @himself65, @addaleax)

  6. github-actions commented on May 31, 2026

    @github-actions
    Contributor

    This issue has been marked as stale due to 210 days of inactivity.
    It will be automatically closed in 30 days if no further activity occurs. If this is still relevant, please leave a comment or update it to keep it open.

  7. added
    staleIssues and PRs marked stale due to inactivity and scheduled for automatic closure.
    on May 31, 2026
  8. github-actions commented on Jul 1, 2026

    @github-actions
    Contributor

    This issue has been automatically closed after 30 days of inactivity following its stale status (no activity for a total of 240 days).
    If this is still relevant, feel free to reopen it or leave a comment with additional details so we can continue the discussion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    staleIssues and PRs marked stale due to inactivity and scheduled for automatic closure.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions