如果我在角tsconfig.json项目的4+文件中设置了这个值:
"noImplicitAny": true,
...and导入它以用于单元测试中:
import { Spy } from "karma-jasmine";
...I在npm test上看到了这个控制台错误
ERROR in C:/test-project/src/app/components/test/test.component.spec.ts (1,21):
Could not find a declaration file for module 'karma-jasmine
我试图在一个组件上编写一些单元测试,将一些服务注入其中,以便从服务器加载数据。数据在OnInit()方法上加载到这个组件中。我正在尝试该服务方法使用spyOn返回一些虚拟数据。以下是单元测试的设置-
let comp: MyComponent;
let fixture: ComponentFixture<MyComponent>;
let staticDataService: any;
let spy: jasmine.Spy;
let allCountries: string[];
describe('MyComponent', () => {
befor
我试图为我的测试创建一个间谍对象:
let spy: jasmine.SpyObj<GeneralService>;
不幸的是,我在运行ng test时遇到了这个错误
Namespace 'jasmine' has no exported member 'SpyObj'
此外,WebStorm将SpyObj标记为未解析变量。
这是我的devDependencies package.json
"devDependencies": {
"@angular/cli": "1.7.3",
我正在尝试学习如何使用Jasmine和Sinon来测试主干应用程序,并且我一直在关注。然而,我遇到了一个我不知道如何解决的问题。
很可能解决方案很简单,但我需要一些指导...
在我的project.spec.js文件中,这是导致问题的代码:
it("should not save when name is empty", function() {
var eventSpy = sinon.spy();
this.project.bind("error", eventSpy);
this.project.save({"name
我想以与angular示例相同的方式将服务注入到serviceSpy中。Angular 9
let masterService: MasterService;
let valueServiceSpy: jasmine.SpyObj<ValueService>;
beforeEach(() => {
const spy = jasmine.createSpyObj('ValueService', ['getValue']);
TestBed.configureTestingModule({
// Provide both the servi
describe('Controller:explorerCtrl', function() {
'use strict';
var explorerCtrl;
var explorerService;
var listService;
var scope;
var $httpBackend;
var aggregatedPods_;
var $state;
var $mdDialog;
var StateService;
var spy;
beforeEach(module(
'ui.router', explorer, kpi,
list)
我正在尝试测试一种不返回任何内容的方法。该方法调用服务来执行Http POST。我模拟了我的服务,并将它设置为SpyOn中的一个参数。SpyOn调用中的第二个参数是包含post操作的方法的名称。在本例中,方法名为postSkillforMember。当我运行ng测试时,Jasmine列表失败引发以下错误:
Jasmine列出的失败列表:
AddSkillModalComponent > Testing addSkill() success
Error: <spyOn> : could not find an object to spy upon for postSkillfo
我想为照片上传方法写一个单元测试。但是我得到了Failed: this.task.snapshotChanges(...).pipe is not a function TypeError: this.task.snapshotChanges(...).pipe is not a function错误。
组件
public startUpload(event: FileList) {
const file: File = event.item(0);
const pathRef = `users/${this.uid}`;
this.task = thi
我正在尝试学习如何使用Jasmine进行单元测试。我做了一个非常简单的例子,我试着测试一个方法在jquery click事件被触发时会被调用。我好像不能让它起作用。有人能帮帮忙吗?非常感谢!
我得到以下错误:
ReferenceError: Butthead is not defined in http://localhost:4243/spec/buttheadSpec.js (line 11)
和
spyOn could not find an object to spy upon for responseAlert()
下面是代码
function Butthead(){
}
Butt