Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
coopwire-hypothesis
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
孙灵跃 Leon Sun
coopwire-hypothesis
Commits
62b99843
Commit
62b99843
authored
May 29, 2019
by
Robert Knight
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add tests for `warnOnce` utility
parent
e5824a34
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
34 additions
and
1 deletion
+34
-1
warn-once-test.js
src/sidebar/util/test/warn-once-test.js
+26
-0
warn-once.js
src/sidebar/util/warn-once.js
+8
-1
No files found.
src/sidebar/util/test/warn-once-test.js
0 → 100644
View file @
62b99843
'use strict'
;
const
warnOnce
=
require
(
'../warn-once'
);
describe
(
'warnOnce'
,
()
=>
{
beforeEach
(()
=>
{
sinon
.
stub
(
console
,
'warn'
);
warnOnce
.
reset
();
});
afterEach
(()
=>
{
console
.
warn
.
restore
();
});
it
(
'outputs a warning only the first time a given string is passed'
,
()
=>
{
warnOnce
(
'something is fishy'
);
assert
.
calledWith
(
console
.
warn
,
'something is fishy'
);
console
.
warn
.
reset
();
warnOnce
(
'something is fishy'
);
assert
.
notCalled
(
console
.
warn
);
warnOnce
(
'something else is wrong'
);
assert
.
calledWith
(
console
.
warn
,
'something else is wrong'
);
});
});
src/sidebar/util/warn-once.js
View file @
62b99843
'use strict'
;
'use strict'
;
cons
t
shownWarnings
=
{};
le
t
shownWarnings
=
{};
/**
/**
* Log a warning if it has not already been reported.
* Log a warning if it has not already been reported.
*
*
* This is useful to avoid spamming the console if a warning is emitted in a
* context that may be called frequently.
*
* @param {string} warning
* @param {string} warning
*/
*/
function
warnOnce
(
warning
)
{
function
warnOnce
(
warning
)
{
...
@@ -15,4 +18,8 @@ function warnOnce(warning) {
...
@@ -15,4 +18,8 @@ function warnOnce(warning) {
shownWarnings
[
warning
]
=
true
;
shownWarnings
[
warning
]
=
true
;
}
}
warnOnce
.
reset
=
()
=>
{
shownWarnings
=
{};
};
module
.
exports
=
warnOnce
;
module
.
exports
=
warnOnce
;
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment