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

Using spread with mocha doesn't work as expected #9296

Open
zazoomauro opened this Issue Jan 8, 2019 · 1 comment

Comments

Projects
None yet
2 participants
@zazoomauro
Copy link

zazoomauro commented Jan 8, 2019

Bug Report

Current Behavior
When I'm running mocha on some code using spread ... there is an error coming out:
ReferenceError: arrayWithoutHoles is not defined

Input Code

  • REPL or Repo link if applicable:

Source Code

export default class SomeClass {
  async someMethod(array) {
    const newArray = []
    newArray.push(...array)
    return newArray
  }
}

Test

import chai from 'chai';
import cp from 'chai-as-promised';
import {beforeEach, describe, it} from 'mocha';
import SomeClass from './someClass';

describe('SomeClass', () => {
  chai.use(cp);
  const expect = chai.expect;
  let someClass;

  beforeEach(() => {
    someClass = new SomeClass();
  });

  describe('someMethod', () => {
    it('should retrieve an array', () => {
      // Arrange.
      const array = [1,2,3]

      // Act.
      const actual = someClass.someMethod(array)

      // Assert.
      return expect(actual).to.eventually.equals(array);
    });
  });
});
"test": "cross-env NODE_ENV=test mocha"

Expected behavior/code
In theory, the test should be green or red but is throwing an exception
ReferenceError: arrayWithoutHoles is not defined at _toConsumableArray (someClass.js:8:36)

Babel Configuration (.babelrc, package.json, cli command)

{
  "presets": [
    [
      "@babel/preset-env",
      {
        "exclude": [
          "babel-plugin-transform-classes"
        ]
      }
    ]
  ],
  "plugins": [
    "@babel/plugin-proposal-object-rest-spread"
  ]
}

package.json

"devDependencies": {
    "@babel/cli": "^7.2.3",
    "@babel/core": "^7.2.2",
    "@babel/plugin-proposal-object-rest-spread": "^7.2.0",
    "@babel/preset-env": "^7.2.3",
    "@babel/register": "^7.0.0",
    ...
  }

Environment

  • Babel version(s): 7
  • Node/npm version: 11
  • OS: OSX Mojave
  • Monorepo: npm
  • How you are using Babel: cli
@babel-bot

This comment has been minimized.

Copy link
Collaborator

babel-bot commented Jan 8, 2019

Hey @zazoomauro! We really appreciate you taking the time to report an issue. The collaborators
on this project attempt to help as many people as possible, but we're a limited number of volunteers,
so it's possible this won't be addressed swiftly.

If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack
community
that typically always has someone willing to help. You can sign-up here
for an invite.

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