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

describe.only() does not work when string is the same as another describe() block #1834

Closed
bguiz opened this issue Aug 15, 2015 · 5 comments
Closed

Comments

@bguiz
Copy link

bguiz commented Aug 15, 2015

With two describe() blocks that have identical strings,
when one of them is a describe.only(),
only that one's tests should run,
however, both of them run.

describe.only('foo', function() {
  it('bar', function(done) { done(); });
});

describe('foo', function() {
  it('baz', function(done) { done(); });
});
[foo]
  ✓ bar

[foo]
  ✓ baz

More worryingly, if there are other unrelated describe() blocks,
they also seems to get run for no reason as well.

describe.only('foo', function() {
  it('bar', function(done) { done(); });
});

describe('foo', function() {
  it('baz', function(done) { done(); });
});

describe('completely', function() {
  it('unrelated', function(done) { done(); });
});
[foo]
  ✓ bar

[foo]
  ✓ baz

[completely]
  ✓ unrelated

Changing the string in describe() causes the behaviour to be normal

describe.only('foo only', function() {
  it('bar', function(done) { done(); });
});

describe('foo', function() {
  it('baz', function(done) { done(); });
});
[foo only]
  ✓ bar
@boneskull
Copy link
Contributor

currently expected behavior, see #1807

@bguiz
Copy link
Author

bguiz commented Aug 20, 2015

Do you mean that once PR #1807 gets merged the behaviour will be correct?

(Cos the examples that I have above certainly do not seem like they are right at all)

@Kequc
Copy link

Kequc commented Apr 14, 2017

I have a describe block identified with AttachmentMeta being run when I set .only on a describe block identified as Attachment.

describe.only('Attachment', function() {
    [etc..]
});

describe('AttachmentMeta', function() {
    [etc..]
});

Tests are run from Attachment and AttachmentMeta. This is not desired behaviour, I expect only tests from one describe block to be run. These two areas of my tests describe completely different areas of the application.

@Kequc
Copy link

Kequc commented Apr 14, 2017

Separately: I have a describe block identified with Models Attachment and an empty one identified as Models Body, both with .only set.

describe.only('Models Attachment', function() {
    [etc..]
});

describe.only('Models Body', function() {
});

0 tests are run.

With the .only decorator behaving erratically, or in unexpected ways like this, it is difficult to trust all of my tests are being visited in normal usage.

@ScottFreeCode
Copy link
Contributor

Ensure you are using the latest version of Mocha (and remove any global install, as global versions of Mocha are not handled correctly at the present time). These issues should be fixed in version 3. If they are not, please open a new issue.

(If these are used in the earlier versions of Mocha, the first one will behave as described because only is implemented as a string match against the full suite+test title list, and the second because the last only run is the one that takes precedence and therefore the empty suite is the only one being run.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants