test: stabilize MediaPlayerContainer play-count harness

This commit is contained in:
Jonathan Baldie 2026-05-02 09:59:01 +01:00
parent 058e774351
commit d7eb4dec9b

View file

@ -256,16 +256,25 @@ describe('MediaPlayerContainer', () => {
}
cy.stub(win.HTMLMediaElement.prototype, 'load').callsFake(function load() {
if (this.__absLoadedMetadataDispatched) return
this.__absLoadedMetadataDispatched = true
this.dispatchEvent(new win.Event('loadedmetadata'))
}).as('mediaLoad')
cy.stub(win.HTMLMediaElement.prototype, 'play').callsFake(function play() {
if (this.__absIsPlaying) return Promise.resolve()
this.__absIsPlaying = true
this.dispatchEvent(new win.Event('play'))
this.dispatchEvent(new win.Event('playing'))
return Promise.resolve()
}).as('mediaPlay')
}).as('mediaPlayCall')
cy.stub(win.HTMLMediaElement.prototype, 'pause').callsFake(function pause() {
if (!this.__absIsPlaying) return
this.__absIsPlaying = false
this.dispatchEvent(new win.Event('pause'))
}).as('mediaPause')
})
@ -284,7 +293,7 @@ describe('MediaPlayerContainer', () => {
cy.get('button[aria-label="Play"]').click()
cy.get('@mediaLoad').should('have.been.called')
cy.get('@mediaPlay').should('have.been.calledOnce')
cy.get('@mediaPlayCall').should('have.been.calledTwice')
cy.get('@createMediaElementSource').should('have.been.calledOnce')
cy.get('audio#audio-player').should(($audio) => {
expect($audio[0].src).to.include(FIXTURE_URL)