-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
modify Mocha constructor to accept options.global or options.globals #3914
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
Merged
Merged
Changes from 6 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
59dece3
accept options.global or options.globals
pascalpp 738fcda
added tests for options.global and options.globals
pascalpp 48e776d
skip new tests to verify test failure
pascalpp d85f580
re-enable options.global tests
pascalpp 9b8b611
consume options.global or options.globals in the constructor. filter …
pascalpp f65b75e
fixed API doc link
pascalpp f973cc0
update comment
pascalpp e1a79a6
added third element to test addition
pascalpp 04f6526
added quotes around options.global and options.globals
pascalpp File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,6 +21,7 @@ describe('Mocha', function() { | |
| sandbox.stub(Mocha.prototype, 'useColors').returnsThis(); | ||
| sandbox.stub(utils, 'deprecate'); | ||
| sandbox.stub(Mocha.prototype, 'timeout').returnsThis(); | ||
| sandbox.stub(Mocha.prototype, 'globals').returnsThis(); | ||
| }); | ||
|
|
||
| describe('when "useColors" option is defined', function() { | ||
|
|
@@ -64,6 +65,44 @@ describe('Mocha', function() { | |
| ); | ||
| }); | ||
| }); | ||
|
|
||
| describe('when options.global is provided', function() { | ||
juergba marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| it('should pass options.global to #globals()', function() { | ||
| // eslint-disable-next-line no-new | ||
juergba marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| new Mocha({global: ['singular']}); | ||
| expect(Mocha.prototype.globals, 'to have a call satisfying', [ | ||
| ['singular'] | ||
| ]).and('was called once'); | ||
| }); | ||
| it('should delete mocha.options.global', function() { | ||
|
Contributor
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 would not test the deletion, but it's ok ... |
||
| var mocha = new Mocha({global: ['singular']}); | ||
| expect(mocha.options.global, 'to be', undefined); | ||
| }); | ||
| }); | ||
|
|
||
| describe('when options.globals is provided', function() { | ||
| it('should pass options.globals to #globals()', function() { | ||
| // eslint-disable-next-line no-new | ||
| new Mocha({globals: ['plural']}); | ||
| expect(Mocha.prototype.globals, 'to have a call satisfying', [ | ||
| ['plural'] | ||
| ]).and('was called once'); | ||
| }); | ||
| }); | ||
|
|
||
| describe('when options.global AND options.globals are provided', function() { | ||
| it('should pass options.global to #globals(), ignoring options.globals', function() { | ||
| // eslint-disable-next-line no-new | ||
| new Mocha({global: ['singular'], globals: ['plural']}); | ||
| expect(Mocha.prototype.globals, 'to have a call satisfying', [ | ||
| ['singular'] | ||
| ]).and('was called once'); | ||
| }); | ||
| it('should delete mocha.options.global', function() { | ||
| var mocha = new Mocha({global: ['singular'], globals: ['plural']}); | ||
| expect(mocha.options.global, 'to be', undefined); | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| describe('#allowUncaught()', function() { | ||
|
|
@@ -174,6 +213,14 @@ describe('Mocha', function() { | |
| expect(mocha.options.globals, 'to contain', elem, elem2); | ||
| expect(mocha.options.globals, 'to have length', elems.length); | ||
| }); | ||
|
|
||
| it('should not have duplicates', function() { | ||
| var mocha = new Mocha({globals: [elem, elem2]}); | ||
| var elems = [elem, elem2]; | ||
juergba marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| mocha.globals(elems); | ||
| expect(mocha.options.globals, 'to contain', elem, elem2); | ||
| expect(mocha.options.globals, 'to have length', elems.length); | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.