Files
wgenerator/src/app/modules/songs/song/edit/edit-song.guard.spec.ts
2026-03-10 00:05:15 +01:00

32 lines
1019 B
TypeScript

import {TestBed} from '@angular/core/testing';
import {EditSongGuard} from './edit-song.guard';
describe('EditSongGuard', () => {
let guard: EditSongGuard;
beforeEach(() => {
void TestBed.configureTestingModule({});
guard = TestBed.inject(EditSongGuard);
});
it('should be created', () => {
expect(guard).toBeTruthy();
});
it('should allow navigation when there is no nested editSongComponent', () => {
const result = guard.canDeactivate({editSongComponent: null} as never, {} as never, {} as never, {} as never);
expect(result).toBeTrue();
});
it('should delegate to askForSave on the nested editSongComponent', async () => {
const nextState = {url: '/songs'} as never;
const askForSave = jasmine.createSpy('askForSave').and.resolveTo(true);
const result = await guard.canDeactivate({editSongComponent: {askForSave}} as never, {} as never, {} as never, nextState);
expect(askForSave).toHaveBeenCalledWith(nextState);
expect(result).toBeTrue();
});
});