Skip to content
This repository was archived by the owner on Feb 28, 2023. It is now read-only.

Commit dd6b254

Browse files
committed
add network idle solution
1 parent 25b3b8c commit dd6b254

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

cypress/integration/05-xhr/answer-intercept-spec.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,4 +469,33 @@ describe('intercept', () => {
469469
})
470470
})
471471
})
472+
473+
context('network idle', () => {
474+
beforeEach(() => {
475+
// let's reset the server to always have 2 todos
476+
resetDatabaseTo('two-items.json')
477+
})
478+
479+
it('waits for network to be idle for 1 second', () => {
480+
let lastNetworkAt
481+
cy.intercept('*', () => {
482+
lastNetworkAt = +new Date()
483+
})
484+
// load the page, but delay loading of the data
485+
cy.visit('/?delay=800')
486+
487+
// wait for network to be idle for 1 second
488+
const started = +new Date()
489+
cy.wrap('network idle for 1 sec').should(() => {
490+
const t = lastNetworkAt || started
491+
const elapsed = +new Date() - t
492+
if (elapsed < 1000) {
493+
throw new Error('Network is busy')
494+
}
495+
})
496+
// by now everything should have been loaded
497+
// we can check by using very short timeout
498+
cy.get('.todo-list li', { timeout: 10 }).should('have.length', 2)
499+
})
500+
})
472501
})

cypress/integration/05-xhr/spec.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,10 @@ it('handles todos with blank title', () => {
100100
// having blank spaces or null
101101
// confirm the todo item is shown correctly
102102
})
103+
104+
it('waits for network to be idle for 1 second', () => {
105+
// intercept all requests
106+
// on every intercept set the timestamp
107+
// retry using should(cb) checking the time
108+
// that has passed since the network timestamp
109+
})

0 commit comments

Comments
 (0)