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
61214c92
Unverified
Commit
61214c92
authored
Nov 26, 2019
by
Robert Knight
Committed by
GitHub
Nov 26, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1539 from hypothesis/fix-flakey-resize-test
Fix cause of flakiness in `observeElementSize` test
parents
90e5e1bf
2afcb54a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
4 deletions
+21
-4
observe-element-size-test.js
src/sidebar/util/test/observe-element-size-test.js
+21
-4
No files found.
src/sidebar/util/test/observe
r
-element-size-test.js
→
src/sidebar/util/test/observe-element-size-test.js
View file @
61214c92
...
...
@@ -2,9 +2,28 @@
const
observeElementSize
=
require
(
'../observe-element-size'
);
/**
* Wait for a condition to become true.
*
* @param {() => boolean} callback
*/
function
waitFor
(
callback
)
{
return
new
Promise
(
resolve
=>
{
const
timer
=
setInterval
(()
=>
{
if
(
callback
())
{
clearInterval
(
timer
);
resolve
();
}
},
0
);
});
}
/**
* Give MutationObserver, ResizeObserver etc. a chance to deliver their
* notifications.
*
* This waits for a fixed amount of time. If you can wait for a specific event
* using `waitFor`, you should do so.
*/
function
waitForObservations
()
{
return
new
Promise
(
resolve
=>
setTimeout
(
resolve
,
1
));
...
...
@@ -40,8 +59,7 @@ describe('observeElementSize', () => {
startObserving
();
content
.
innerHTML
=
'<p>different content</p>'
;
await
waitForObservations
();
assert
.
called
(
sizeChanged
);
await
waitFor
(()
=>
sizeChanged
.
called
);
stopObserving
();
sizeChanged
.
reset
();
...
...
@@ -84,8 +102,7 @@ describe('observeElementSize', () => {
// Change the content height, which is not directly observed.
content
.
style
.
minHeight
=
'500px'
;
triggerCheck
();
await
waitForObservations
();
assert
.
called
(
sizeChanged
);
await
waitFor
(()
=>
sizeChanged
.
called
);
sizeChanged
.
reset
();
stopObserving
();
...
...
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