How can I mock the event argument in karma chai sinon mocha ?
it('should have onmute event on tracks', async () => {
if (fakeAudioTracks[0].onmute !== null) {
console.log('before fakeAudioTracks[0] ', fakeAudioTracks[0]);
eventCallbackSpy = Sinon.spy();
subscriptions.events['track:mute'].set(subscription.listener.id, eventCallbackSpy);
fakeAudioTracks[0].enabled = true;
fakeAudioTracks[0].onmute(new Event('mute'));
Sinon.assert.called(eventCallbackSpy);
// expect(eventCallbackSpy.getCall(0).args[0].action).to.be.equal('muted');
console.log('After fakeAudioTracks[0] ', fakeAudioTracks[0]);
expect(eventCallbackSpy.getCall(0).args[0].action).to.be.equal('muted');
}
});
This is my test case, I want to pass an argument fakeAudioTracks[0]
to fakeAudioTracks[0].onmute(new Event('mute'));
this.
My onmute –
export function onmute(event: Event) : void {
console.log('event ', event.target);
const onmuteListeners: eventListeners = subscriptions.events['track:mute'];
for (const entry of onmuteListeners) {
const listener = entry[1];
if (listener) {
listener({
action: 'muted' || 'unmuted', // need to check the event.target and return this.
// action: event.target.enabled === 'true' ? 'muted' : 'unmuted',
track: <MediaStreamTrack> event.target,
});
}
}
}