mardi 20 septembre 2016

Test Angular 2.0.0 component with HTTP request

I have the following Angular 2.0.0 component:

import { Component, OnInit } from '@angular/core';
import { Http } from '@angular/http';

@Component({
  selector: 'app-book-list',
  templateUrl: './book-list.component.html',
  styleUrls: ['./book-list.component.css']
})
export class BookListComponent implements OnInit {
  books: any;

  constructor(private http: Http) { }

  ngOnInit() {
    this.http.get('/api/books.json')
      .subscribe(response => this.books = response.json());
  }

}

How would I test the ngOnInit() function?

I don't want to include the test I've tried so far because I suspect I'm way off the right track and I don't want to bias the answers.

Aucun commentaire:

Enregistrer un commentaire