Skip to content

Commit

Permalink
add test on sound service
Browse files Browse the repository at this point in the history
  • Loading branch information
Babali42 committed Jan 4, 2025
1 parent 388cd9c commit a57d9cf
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions frontend/src/app/services/sound/sound.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,40 @@ import { TestBed } from "@angular/core/testing";
import {LoadingBarService} from "@ngx-loading-bar/core";

describe("sound", () => {
let mockSoundGeneratorService: Partial<SoundGeneratorService>;
let soundService: SoundService;
let soundGeneratorService: SoundGeneratorService;

beforeEach(() => {
const mockSoundGeneratorService = {
getRenderedBuffer: jasmine.createSpy('getRenderedBuffer').and.returnValue(Promise.resolve(new AudioBuffer( {
length: 10,
numberOfChannels: 2,
sampleRate: 44000
})))
};

TestBed.configureTestingModule({
providers: [
SoundService,
{ provide: SoundGeneratorService, useValue: mockSoundGeneratorService },
{
provide: SoundGeneratorService,
useValue: mockSoundGeneratorService
},
LoadingBarService
]
});

soundService = TestBed.inject(SoundService);
soundGeneratorService = TestBed.inject(SoundGeneratorService);
});

it("should create the sound service", () => {
expect(soundService).toBeTruthy();
});

it("should call the soundGenerator once when play twice", async () => {
await soundService.playPause();
// eslint-disable-next-line @typescript-eslint/unbound-method
expect(soundGeneratorService.getRenderedBuffer).toHaveBeenCalledTimes(1);
});
})

0 comments on commit a57d9cf

Please sign in to comment.