Сначала сервис, который я хочу проверить
@Injectable()
export class CheckForUpdateService {
constructor(appRef: ApplicationRef, updates: SwUpdate) {
console.log('CheckForUpdateService started');
// Allow the app to stabilize first, before starting polling for updates with `interval()`.
const appIsStable$ = appRef.isStable.pipe(first(isStable => isStable === true));
const everySixHours$ = interval(6 * 60 * 60 * 1000);
const everySixHoursOnceAppIsStable$ = concat(appIsStable$, everySixHours$);
everySixHoursOnceAppIsStable$.subscribe(() => {
updates.checkForUpdate()
.catch((error) => {
console.error('Service Workers disabled or not supported in this browser');
});
});
}
}
и вот мой тестовый модуль
describe('CheckForUpdateService', () => {
let service: CheckForUpdateService;
// Parameters for constructor
let applicationRefSpy: ApplicationRef;
let swUpdateSpy: SwUpdate;
beforeEach(() => {
applicationRefSpy = jasmine.createSpyObj('ApplicationRef', [''], {
['isStable']: of(true)
});
swUpdateSpy = jasmine.createSpyObj('SwUpdate',
{
['checkForUpdate']: Promise.resolve()
});
TestBed.configureTestingModule({
providers: [
{ provide: ApplicationRef, useValue: applicationRefSpy },
{ provide: SwUpdate, useValue: swUpdateSpy }
]
});
service = TestBed.inject(CheckForUpdateService);
});
it('should be created', () => {
expect(service).toBeTruthy();
});
});
Я получаю сообщение об ошибке:
NullInjectorError: R3InjectorError(CompilerModule)[CheckForUpdateService -> CheckForUpdateService]:
NullInjectorError: No provider for CheckForUpdateService!
error properties: Object({ ngTempTokenPath: null, ngTokenPath: [ 'CheckForUpdateService', 'CheckForUpdateService' ] })
Что такое Я делаю неправильно, и как я могу это исправить? Правильно ли я понимаю, что модульный тест не может найти поставщиков для check-for-update.service?