小编SON*_*TER的帖子

测试Http Service进行多次调用并返回observable而不映射响应

我有一个数据服务,它从服务器获取数据并生成多个请求,然后返回一个可观察数组.我想测试数据.

我尝试做的是在我发送的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)

jasmine angular-http angular-services angular angular-test

8
推荐指数
1
解决办法
1102
查看次数

angular2过渡动画不起作用

我试图将角度过渡应用于元素,但它不起作用.我也添加了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)

angular angular-animations

7
推荐指数
1
解决办法
490
查看次数

为什么是   不工作

我想在添加的名字和姓氏之间添加空格。但是当我运行代码时,它不会增加空间。我也尝试添加 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}&nbsp;&nbsp;&nbsp;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)

html typescript ecmascript-6 angular

6
推荐指数
2
解决办法
2万
查看次数

每条路线的多个组件有角度

我想要做的是,我想同时加载home componentsidebar 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)

angular2-routing angular angular4-router

6
推荐指数
2
解决办法
1万
查看次数

如何以缅甸/缅甸语字体显示网站内容

我有一个网站,用缅甸语为缅甸人民服务.问题是缅甸国家没有使用Unicode格式而是使用Zawgyi格式编码.我网站上的内容显示已损坏.我该如何解决这个问题.

在此输入图像描述

此错误仅在Iphone中出现

css unicode html5 fonts localization

6
推荐指数
1
解决办法
4900
查看次数

RegExp 字符类中的范围乱序

我试图验证使用表达式提交的电子邮件输入^([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)

regex angular2-forms angular

2
推荐指数
1
解决办法
1万
查看次数