我仍在学习如何使用 Karma/Jasmine 编写角度测试。我想为环境的 isDebugMode 返回 false。当我更改它的代码时,它显然有效,但是我如何为此编写测试?我已经设置了一些测试,试图找出如何模拟环境。但似乎没有一个像我认为的那样工作。我想知道是否有人可以解释为什么这些会返回他们所做的值。
import { TestBed, inject } from '@angular/core/testing';
import { LoggerService } from './logger.service';
import { environment } from '../environments/environment';
import { mockEnvironment} from '../environments/environment.mock';
describe('Test', () => {
beforeEach(() => {
spyOn(console, 'error');
spyOn(console, 'warn');
TestBed.configureTestingModule({
providers: [ LoggerService ]
});
});
it('should be created',
inject([LoggerService],
(service: LoggerService) => {
expect(service).toBeTruthy();
}));
it('should always work', function() {
expect(true).toBe(true);
});
it('is the mocked environment returning false', function() {
spyOn(mockEnvironment, 'isDebugMode');
expect(mockEnvironment.isDebugMode).toEqual(false);
});
it('is the environment …Run Code Online (Sandbox Code Playgroud)