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

Nested tests? #62

Closed
matthewmueller opened this issue Sep 20, 2015 · 11 comments
Closed

Nested tests? #62

matthewmueller opened this issue Sep 20, 2015 · 11 comments

Comments

@matthewmueller
Copy link

One thing that's nice about nested tests is being able to support different before, after, beforeEach, and afterEach functions.

Would probably be a pretty large refactor, but I could see API looking like this:

test('a model', function(t, test) {
  test('should do this', function (t) {
      // do test
  }) 
})
@Qix-
Copy link
Contributor

Qix- commented Sep 20, 2015

With the nature of AVA as I understand, I can't imagine this taking much work.

@sindresorhus
Copy link
Member

Shouldn't be very hard. Not sure we want this, though. I've honestly never needed it. You could achieve the same thing with multiple files (which would also be beneficial for parallelism). Do you have a real scenario you could link to where this was useful?

@Qix-
Copy link
Contributor

Qix- commented Sep 21, 2015

👍 for multiple files anyway. I think it's intended to be synonymous with Mocha's describe(), which would definitely be better with multiple files IMO.

@matthewmueller
Copy link
Author

not a big deal either way but files usually correspond 1:1 with what file they're testing. it's often useful when testing say, a user model, to have different bootstrapping functions.

alternatively, this could also be achieved with something along the lines of:

test('a model', function (t) {
  t.before(function() { ... })
})

test('a model', function (t) {
  t.after(function() { ... })
})

which would work without nesting.

@ahdinosaur
Copy link

hey. 🐱 it's worth mentioning that tape supports nested tests with t.test, e.g.

test('a test', function(t) {
  t.test('a sub-test', function (t) {
    // do test
  }) 
})

personally, i think this would be awesome for ava, especially if t.test included all the other methods of test, e.g. .before and .after methods:

test('a test', function(t) {
  t.test.before(function (t) {
    // setup
  })

  t.test.after(function (t) {
    // teardown
  })

  t.test('a sub-test', function (t) {
    // do test
  }) 
})

@dbkaplun
Copy link

+1, would you accept a PR for this?

@sindresorhus
Copy link
Member

I still feel it's an anti-pattern and nobody has convinced me otherwise (hint hint). Having tests in separate files instead of nesting has the benefit of cleaner test files and parallelism.

@vdemedes @kevva Thoughts?

@vadimdemedes
Copy link
Contributor

Honestly, I don't think it's a good idea. It does not look good, it will cause bugs and it does not make much sense to use test as an alternative to describe in mocha.

@matthewmueller
Copy link
Author

closing since there doesn't seem to be much interest by the authors.

@wclr
Copy link

wclr commented Jun 18, 2016

The only good case I see use to have nested is to include (using .only) or exclude (.skip) bunch of tests.

@jamestalmage
Copy link
Contributor

Locking in favor of duplicate #222.

Please move all discussion there.

@avajs avajs locked and limited conversation to collaborators Jun 18, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants