fix missing mock for test

This commit is contained in:
Valere
2025-12-05 18:28:36 +01:00
parent 0a09b8a676
commit 53542ca957
2 changed files with 17 additions and 8 deletions

View File

@@ -98,14 +98,19 @@ describe("Publisher", () => {
(
connection.livekitRoom.localParticipant.createTracks as Mock
).mockResolvedValue([{}, {}]);
).mockResolvedValue([
{
kind: "audio",
mute: vi.fn(),
},
]);
await expect(publisher.createAndSetupTracks()).resolves.not.toThrow();
expect(
connection.livekitRoom.localParticipant.createTracks,
).toHaveBeenCalledOnce();
// failiour due to localParticipant.publishTrack
// failure due to localParticipant.publishTrack
(
connection.livekitRoom.localParticipant.publishTrack as Mock
).mockRejectedValue(Error("testError"));
@@ -114,7 +119,7 @@ describe("Publisher", () => {
new FailToStartLivekitConnection("testError"),
);
// does not try other conenction after the first one failed
// does not try other connection after the first one failed
expect(
connection.livekitRoom.localParticipant.publishTrack,
).toHaveBeenCalledTimes(1);
@@ -145,7 +150,7 @@ describe("Publisher", () => {
expect(
connection.livekitRoom.localParticipant.publishTrack,
).toHaveBeenCalledTimes(3);
).toHaveBeenCalledTimes(2);
});
});

View File

@@ -191,10 +191,14 @@ export class Publisher {
// or only use the low level create/publish APIs and have our own pending publication protection.
// Maybe we could change the livekit api to pre-load tracks without publishing them yet?
// Are we sure this is needed at all? What are the gains?
const isEnabled =
track.kind === Track.Kind.Audio
? this.muteStates.audio.enabled$.value
: this.muteStates.video.enabled$.value;
let isEnabled: boolean;
if (track.kind === Track.Kind.Audio) {
isEnabled = this.muteStates.audio.enabled$.value;
} else if (track.kind === Track.Kind.Video) {
isEnabled = this.muteStates.video.enabled$.value;
} else {
throw new Error("Unsupported track kind " + track.kind);
}
if (!isEnabled) {
// TODO should we also drop it?