-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Refactor out usages of Suite#_onlyTests and Suite#_onlyTests (#3689) #3707
Changes from 5 commits
0e6bf82
a3ab741
4708d62
a083a77
62390b1
734d9da
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,7 +27,7 @@ | |
"default": { | ||
"includeDate": false, | ||
"outputSourceFiles": true | ||
}, | ||
}, | ||
"monospaceLinks": false | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -545,6 +545,89 @@ describe('Suite', function() { | |
expect(suite.timeout(), 'to be', 100); | ||
}); | ||
}); | ||
|
||
describe('hasOnly()', function() { | ||
it('should return true if a test has `only`', function() { | ||
var suite = new Suite('foo'); | ||
var test = new Test('bar'); | ||
|
||
suite.appendOnlyTest(test); | ||
|
||
expect(suite.hasOnly(), 'to be', true); | ||
}); | ||
|
||
it('should return true if a suite has `only`', function() { | ||
var suite = new Suite('foo'); | ||
var nested = new Suite('bar'); | ||
|
||
suite.appendOnlySuite(nested); | ||
|
||
expect(suite.hasOnly(), 'to be', true); | ||
}); | ||
|
||
it('should return true if nested suite has `only`', function() { | ||
var suite = new Suite('foo'); | ||
var nested = new Suite('bar'); | ||
var test = new Test('baz'); | ||
|
||
nested.appendOnlyTest(test); | ||
// `nested` has a `only` test, but `suite` doesn't know about it | ||
suite.suites.push(nested); | ||
|
||
expect(suite.hasOnly(), 'to be', true); | ||
}); | ||
|
||
it('should return false if no suite or test is marked `only`', function() { | ||
var suite = new Suite('foo'); | ||
var nested = new Suite('bar'); | ||
var test = new Test('baz'); | ||
|
||
suite.suites.push(nested); | ||
nested.tests.push(test); | ||
|
||
expect(suite.hasOnly(), 'to be', false); | ||
}); | ||
}); | ||
|
||
describe('.filterOnly()', function() { | ||
it('should filter out all other tests and suites if a test has `only`', function() { | ||
var suite = new Suite('a'); | ||
var nested = new Suite('b'); | ||
var test = new Test('c'); | ||
var test2 = new Test('d'); | ||
|
||
suite.suites.push(nested); | ||
suite.appendOnlyTest(test); | ||
suite.tests.push(test2); | ||
|
||
suite.filterOnly(); | ||
|
||
expect(suite.suites.length, 'to be', 0); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it's best to make a single assertion where possible. you can do this expect(suite, 'to satisfy', {
suites: expect.it('to be empty'),
tests: expect.it('to have length', 1).and('to contain', {title: 'c'})
}); similarly below There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @boneskull I addressed the comments, but I'm curious: why is a single assertion best? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I myself prefer multiple explicit assertions that I don't have to lookup within unexpected config files. Seems like violation of the KISS mentality... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TBH I also prefer multiple explicit assertions, but that's mostly because I'm not very good with unexpected's syntax off the top of my head :) |
||
expect(suite.tests.length, 'to be', 1); | ||
expect(suite.tests[0].title, 'to be', 'c'); | ||
}); | ||
|
||
it('should filter out all other tests and suites if a suite has `only`', function() { | ||
var suite = new Suite('a'); | ||
var nested1 = new Suite('b'); | ||
var nested2 = new Suite('c'); | ||
var test = new Test('d'); | ||
var nestedTest = new Test('e'); | ||
|
||
nested1.appendOnlyTest(nestedTest); | ||
|
||
suite.tests.push(test); | ||
suite.suites.push(nested1); | ||
suite.appendOnlySuite(nested1); | ||
suite.suites.push(nested2); | ||
|
||
suite.filterOnly(); | ||
|
||
expect(suite.suites.length, 'to be', 1); | ||
expect(suite.tests.length, 'to be', 0); | ||
expect(suite.suites[0].title, 'to be', 'b'); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('Test', function() { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How'd this get past prettier?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No idea. Do you know whether my change is correct or the original was correct?