Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/31.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Unit testing 如何为使用欧芹验证的angular2表单编写jasmine单元测试?_Unit Testing_Angular_Jasmine_Karma Runner_Parsley.js - Fatal编程技术网

Unit testing 如何为使用欧芹验证的angular2表单编写jasmine单元测试?

Unit testing 如何为使用欧芹验证的angular2表单编写jasmine单元测试?,unit-testing,angular,jasmine,karma-runner,parsley.js,Unit Testing,Angular,Jasmine,Karma Runner,Parsley.js,我正在尝试为我正在编写的angular2应用程序使用欧芹验证,并想编写一些jasmine单元测试。我想确保以正确的方式验证输入 我正试图写一个小测试,但我认为我的问题是我不能加载欧芹。我正在运行karma runner,并尝试将其包含在配置文件中 这是我的测试文件: /// 从“@angular/core”导入{Component,DebugElement,AfterViewInit}; 从“@angular/platform browser”导入{By}”; 从“@angular/core/

我正在尝试为我正在编写的angular2应用程序使用欧芹验证,并想编写一些jasmine单元测试。我想确保以正确的方式验证输入

我正试图写一个小测试,但我认为我的问题是我不能加载欧芹。我正在运行karma runner,并尝试将其包含在配置文件中

这是我的测试文件:

///
从“@angular/core”导入{Component,DebugElement,AfterViewInit};
从“@angular/platform browser”导入{By}”;
从“@angular/core/testing”导入{ComponentFixture,TestBed,async};
从'@angular/forms'导入{FormsModule};
从“@angular/core/testing”导入{ComponentFixtureAutoDetect};
从“@angular/platform browser/testing/browser util”导入{dispatchEvent};
声明var jQuery:any;
描述(“StringLengthValidationApp”,()=>{
在每个之前(()=>{
TestBed.configureTestingModule({
导入:[FormsModule],
声明:[StringLengthValidationApp],
供应商:[
{提供:ComponentFixtureAutoDetect,useValue:true}
]
});
});
beforeach(异步(()=>{
TestBed.compileComponents();
}));
它(“应该起作用”,()=>{
让fixture=TestBed.createComponent(StringLengthValidationApp);
fixture.detectChanges();
返回fixture.whenStable()。然后(()=>{
const inputName='quick BROWN fox';
让nameInput=fixture.debugElement.query(By.css('input')).nativeElement;
nameInput.value=inputName;
nameInput.dispatchEvent(新事件('input'));
fixture.detectChanges();
设second=fixture.debugElement.query(By.css('textarea')).nativeElement;
second.value=inputName;
第二,dispatchEvent(新事件(“输入”);
fixture.detectChanges();
console.log(fixture.nativeElement);
let errors=fixture.debugElement.queryAll(By.css(“ul”);
expect(errors.length).toBe(1);
});
});
});
@组成部分({
选择器:“日期验证应用程序”,
模板:`
在这里写点东西
`
})
类StringLengthValidationApp{

}
我想我通过简单地添加 'node_modules/parsleyjs/dist/parsley.js',
在我的karma.conf.js中的文件部分

我想我通过简单地添加 'node_modules/parsleyjs/dist/parsley.js',
在我的karma.conf.js文件部分

我想我通过简单地在我的karma.conf.js文件部分添加'node_modules/parsleyjs/dist/parsley.js'解决了这个问题。我想我通过简单地在我的karma.conf.js文件部分添加'node_modules/parsleyjs/dist/parsley.js'解决了这个问题