Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

126
Views
cómo arreglar los oyentes llamados más de una vez

Cómo verificar si el oyente ya está presente, eventCallbackSpyTrack se llama 2 veces al parecer. ¿Cuándo alguien se suscribe a la misma pista más de una vez? Supongo que todos los oyentes de la pista llamaron más de una vez, ¿Cómo arreglar esto?

 // expect(eventCallbackSpyTrack.calledOnce).to.eq(true);

eventCallbackSpyTrack se llama 2 veces, eventCallbackSpyTrack.callCount es 2 pero debería ser 1

Cómo arreglar esto ? Intenté eliminar removeEventListener pero esto no funciona. Por favor ayuda.

 async subscribe(eventName: string, listener: () => void): Promise<subscription> { const subscriptionListener = { id: uuidv4(), method: listener, }; subscriptions.events[eventName].set(subscriptionListener.id, { module: 'track', method: subscriptionListener.method, }); const thisEventListeners = subscriptions.events[eventName]; switch (eventName) { case 'track:mute': { if (thisEventListeners.size >= 1) { this.#mediaStreamTrack.addEventListener('mute', (event) => { trackMutePublisher(event, this, 'track'); }); } break; } default: break; } return new Promise((resolve) => { resolve({ type: eventName, listener: subscriptionListener, }); }); }

En mi prueba unitaria dice

 // expect(eventCallbackSpyTrack.calledOnce).to.eq(true);

eventCallbackSpyTrack se llama 2 veces, eventCallbackSpyTrack.callCount es 2 pero debería ser 1

prueba de unidad -

 describe.only('track mute event & publisher', () => { before(async () => { [videoTrack] = (await navigator.mediaDevices.getUserMedia({video: true})).getVideoTracks(); track = new Track(videoTrack as MediaStreamTrack); setupMediaTrackMocks(); subscription = await track.subscribe('track:mute', eventCallbackSpyTrack); subscription2 = await track.subscribe('track:mute', eventCallbackSpyTrack2); }); after(() => { resetMediaTrackMocks(); }); it('should have called the callback once', () => { expect(subscription.listener.method).to.be.equal(eventCallbackSpyTrack); expect(subscriptions.events['track:mute'].get(subscription.listener.id)?.method).to.be.equal(eventCallbackSpyTrack); expect(subscription2.listener.method).to.be.equal(eventCallbackSpyTrack2); expect(subscriptions.events['track:mute'].get(subscription2.listener.id)?.method).to.be.equal(eventCallbackSpyTrack2); track.getMediaStreamTrack().dispatchEvent(new Event('mute')); Sinon.assert.called(eventCallbackSpyTrack); // expect(eventCallbackSpyTrack.calledOnce).to.eq(true); expect(eventCallbackSpyTrack.callCount).to.be.equal(1); });

Intenté eliminar removeEventListener pero esto no funciona. Por favor ayuda.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!