Skip to content

Unable to delete things from global. #3152

@gdborton

Description

@gdborton

Do you want to request a feature or report a bug?
Bug

What is the current behavior?
delete global.someProp doesn't work.

If the current behavior is a bug, please provide the steps to reproduce and either a repl.it demo through https://repl.it/languages/jest or a minimal repository on GitHub that we can yarn install and yarn test.

Repl.it - https://repl.it/GXd3

const assert = require('assert');

describe('removing stuff from the global object', () => {
  describe(`via 'delete global.prop'`, () => {
    it('should set the value to undefined', () => {
      global.someValue = 'asdf';
      assert.equal(global.someValue, 'asdf');
      delete global.someValue;
      assert.equal(global.someValue, undefined);
    });
  });

  describe(`via 'global.prop = undefined;'`, () => {
    it('should set the value to undefined', () => {
      global.someValue2 = 'asdf';
      assert.equal(global.someValue2, 'asdf');
      global.someValue2 = undefined;
      assert.equal(global.someValue2, undefined);
    });
  });
});

What is the expected behavior?
delete global.someProp should make global.someProp === undefined true.

This works in mocha, jasmine, plain old node, and I think it works when running via vm. We're investigating a move to Jest, but are running into some subtle issues related to this.

For example this function in enzyme doesn't behave correctly - https://github.com/airbnb/enzyme/blob/master/src/Utils.js#L213

We could attempt to work around this, but I feel like this will repeatedly come up in our codebase and will lead to lots of wasted time.

Please provide your exact Jest configuration and mention your Jest, node, yarn/npm version and operating system.
node - v4.6.2
npm - 2.15.11
jest - v19.0.0
os - OSX Sierra v10.12.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions