Skip to content

this.test.fullTitle() changes when using --watch #3847

@fatso83

Description

@fatso83

Prerequisites

  • Checked that your issue hasn't already been filed by cross-referencing issues with the faq label
  • Checked next-gen ES issues and syntax problems by using the same environment and/or transpiler configuration without Mocha to ensure it isn't just a feature that actually isn't supported in the environment in question or a bug in your code.
  • 'Smoke tested' the code to be tested by running it outside the real test suite to get a better sense of whether the problem is in the code under test, your usage of Mocha, or Mocha itself
  • Ensured that there is no discrepancy between the locally and globally installed versions of Mocha. You can find them with: node node_modules/.bin/mocha --version(Local) and mocha --version(Global). We recommend that you not install Mocha globally.

Description

Adding --watch means this.test.fullTitle() prepends a space (' ') on consecutive runs.

Steps to Reproduce

git clone https://gist.github.com/fatso83/d6ef639119bc497cbc8db2e2a950e441 name-issue
cd name-issue/
npm i
npm test
sleep 2;
touch demo.test.js 

Will result in

1..1
ok 1 Outer TEST
# tests 1
# pass 1
# fail 0

  1..1
not ok 1  Outer TEST
  'Outer TEST' == ' Outer TEST'
  AssertionError [ERR_ASSERTION]: 'Outer TEST' == ' Outer TEST'
      at Context.<anonymous> (demo.test.js:7:16)
# tests 1
# pass 0
# fail 1

The actual test looks like this:

describe("Outer", function() {
    it("TEST", (function() {
        assert.equal('Outer TEST',this.test.fullTitle());
    }));
});

Expected behavior: [What you expect to happen]
No errors - the full title should stay the same

Actual behavior: [What actually happens]

A space gets prepended

Reproduces how often: [What percentage of the time does it reproduce?]
100%

Versions

6.0.2

$ mocha --version
6.0.2

$ node --version
v11.11.0

$ lsb_release  -a
Distributor ID:	Ubuntu
Description:	Ubuntu 18.04.2 LTS
Release:	18.04
Codename:	bionic

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: buga defect, confirmed by a maintainer

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions