我有一个数据服务,它从服务器获取数据并生成多个请求,然后返回一个可观察数组.我想测试数据.
我尝试做的是在我发送的mockrespone数组中包含两个observables我不知道这是否是测试数据的正确方法.
但测试失败,尤其是异步测试块中的最后三个测试
重要提示:我想测试一下,当将charId设置为falsy并将comicsId设置为falsy时,调用方法,订阅它返回的observable,在你模拟了http后,你会得到一个包含两个预期响应的数组.如果charId是真实的,则与预期的4个响应相同.当comicsId真实时,6个预期的响应也是如此
//获取数据的服务
getChar(): Observable<any> {
const Observables = [];
Observables.push(this.http.get('https://gateway.marvel.com:443/v1/public/characters?apikey'));
Observables.push(this.http.get('https://gateway.marvel.com:443/v1/public/comics?apikey'));
if (this.charId) {
Observables.push(this.http.get(`${this.urlChar}${this.charId}${this.apiKey}`));
Observables.push(this.http.get(`${this.urlChar}${this.charId}/comics${this.apiKey}`));
}
if (this.comicsId) {
Observables.push(this.http.get(`${this.urlCom}${this.comicsId}${this.apiKey}`));
Observables.push(this.http.get(`${this.urlCom}${this.comicsId}/creators${this.apiKey}`));
}
console.log([Observable, Observable]);
return Observable.forkJoin(Observables);
}
}
Run Code Online (Sandbox Code Playgroud)
//我的考试
import { async, ComponentFixture, TestBed, getTestBed, inject } from '@angular/core/testing';
import { MockBackend, MockConnection } from '@angular/http/testing';
import { DataService } from './data.service';
import {
BaseRequestOptions, Http, XHRBackend, HttpModule,
Response, ResponseOptions, RequestMethod
} from '@angular/http';
import { Observable } from 'rxjs/Observable';
describe('DataService', () => {
let …
Run Code Online (Sandbox Code Playgroud) 我试图将角度过渡应用于元素,但它不起作用.我也添加了web-animation-js但仍然没有效果.在onMouseleave和onMouseover函数上添加了实现
// package.json
"web-animations-js": "^2.3.1",
Run Code Online (Sandbox Code Playgroud)
//项目清单
<li class="list-group-item" (mouseover)="onMouseover()" (mouseleave)="onMouseleave()" [@usrSt]="st" [routerLink]= "['/users', i+1, person.name]" *ngFor="let person of (personsList | filter:coursestat:'chosenCourse'); let i = index">
Run Code Online (Sandbox Code Playgroud)
//列表组件
@Component({
selector: 'app-list',
templateUrl: './list.component.html',
styleUrls: ['./list.component.css'],
animations: [
trigger('usrSt', [
state('active', style({ 'background-color': '#cfd8dc' })),
state('inactive', style({ 'bacckground-color': '#fff' })),
transition('active => inactive', animate('1400ms ease-in')),
transition('inactive => active', animate('400ms ease-out'))
])
]
})
export class ListComponent implements OnInit, OnDestroy {
public personsList;
@Input() id;
st;
@Input() coursestat: string;
constructor(private getDt: InputDataService) {
} …
Run Code Online (Sandbox Code Playgroud) 我想在添加的名字和姓氏之间添加空格。但是当我运行代码时,它不会增加空间。我也尝试添加 tab sapce 但它没有正确渲染。字符集设置为 utf-8,可以在附加的 html 中看到
export class AppComponent implements OnInit {
firstName: string;
lastName: string;
title: string;
clicked: boolean;
ngOnInit() {
this.firstName = `John`;
this.lastName = `Doe`;
}
printDetails(frstnm: HTMLInputElement, lstnm: HTMLInputElement, event: any): void {
this.firstName = frstnm.value || this.firstName;
this.lastName = lstnm.value || this.lastName;
this.title = `First Name is: ${this.firstName} Last Name is: ${this.lastName}`;
event.preventDefault();
this.clicked = true;
}
isVisible() {
const classes = {
display : this.clicked
}
return classes;
}
}
Run Code Online (Sandbox Code Playgroud)
<!doctype html>
<html lang="en"> …
Run Code Online (Sandbox Code Playgroud)我想要做的是,我想同时加载home component
和sidebar component
。
const appRoutes: Routes = [
{
path: '', component: HomeComponent, children: [{
path: 'sidebar', component: SidebarComponent, children: [
{ path: 'about', component: AboutComponent },
{ path: 'clients', component: ClientsComponent },
{ path: 'services', component: ServicesComponent },
{ path: 'contact', component: ContactComponent },
{ path: 'datatable', component: DataComponent }
]
}]
}
Run Code Online (Sandbox Code Playgroud) 我试图验证使用表达式提交的电子邮件输入^([a-zA-Z0-9_\-\.]+)@([a-zA-Z0-9_\-\.]+)\.([a-zA-Z]{2,5})$
,但它引发了错误 Range out of order in character class at RegExp
。我如何使用该表达式进行验证
ngOnInit() {
// created FormGroup using FormBuilder
this.courseForm = this.fb.group({
username: [null, [Validators.required, Validators.pattern('^[a-z0-9_-]{3,16}$')]],
email: [null, [Validators.required, Validators.pattern('^([a-zA-Z0-9_\-\.]+)@([a-zA-Z0-9_\-\.]+)\.([a-zA-Z]{2,5})$')]],
address: (null),
select: (null)
});
Run Code Online (Sandbox Code Playgroud) angular ×5
angular-http ×1
angular-test ×1
css ×1
ecmascript-6 ×1
fonts ×1
html ×1
html5 ×1
jasmine ×1
localization ×1
regex ×1
typescript ×1
unicode ×1