{"id":383055,"date":"2024-06-29T04:39:40","date_gmt":"2024-06-29T04:39:40","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=383055"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=383055","title":{"rendered":"<span>\u0422\u0435\u0441\u0442\u0438\u0440\u0443\u0435\u043c Angular \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435. \u0427\u0430\u0441\u0442\u044c 2. \u0422\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0441\u0435\u0440\u0432\u0438\u0441\u0430<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/eea\/fc8\/24c\/eeafc824c553b6a2ae99e44cf864d6fd.png\" width=\"683\" height=\"423\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/eea\/fc8\/24c\/eeafc824c553b6a2ae99e44cf864d6fd.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0412 \u043f\u0440\u043e\u0448\u043b\u043e\u0439 <a href=\"https:\/\/habr.com\/ru\/post\/575644\/\" rel=\"noopener noreferrer nofollow\">\u0441\u0442\u0430\u0442\u044c\u0435<\/a>, \u044f \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u043b \u043a\u0430\u043a \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442. \u0422\u0435\u043f\u0435\u0440\u044c \u0436\u0435 \u043a\u043e\u0441\u043d\u0435\u043c\u0441\u044f \u0432\u043e\u043f\u0440\u043e\u0441\u0430 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0441\u0435\u0440\u0432\u0438\u0441\u0430. <\/p>\n<h2>\u0412\u0441\u0442\u0443\u043f\u043b\u0435\u043d\u0438\u0435<\/h2>\n<p>\u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0442\u0430\u043a \u0436\u0435, \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u044b \u0438\u0434\u0443\u0449\u0438\u0435 \u0438\u0437 &#171;\u043a\u043e\u0440\u043e\u0431\u043a\u0438&#187;, \u0442\u0430\u043a\u0438\u0435 \u043a\u0430\u043a Karma \u0438 Jasmine. <\/p>\n<p>\u0412\u043a\u0440\u0430\u0442\u0446\u0435 \u043f\u043e\u0432\u0442\u043e\u0440\u044e \u0447\u0442\u043e \u044d\u0442\u043e \u0437\u0430 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u044b: Karma \u044d\u0442\u043e \u0442\u0430\u043a \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u043c\u044b\u0439 \u0442\u0435\u0441\u0442 \u0440\u0430\u043d\u043d\u0435\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043d\u0430\u043c \u043d\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0442\u044c \u0442\u043e \u043d\u0430 \u043a\u0430\u043a\u0438\u0445 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430\u0445 \u0438\u043b\u0438 \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0430\u0445 \u0431\u0443\u0434\u0443\u0442 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c\u0441\u044f \u0442\u0435\u0441\u0442\u044b \u0438 \u043a\u0430\u043a\u0438\u0435 \u0442\u0435\u0441\u0442\u043e\u0432\u044b\u0435 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0438 \u0438 \u043f\u043b\u0430\u0433\u0438\u043d\u044b, \u0431\u0443\u0434\u0443\u0442 \u0443\u0447\u0430\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0432 \u0442\u0435\u0441\u0442\u0430\u0445. Jasmine \u044d\u0442\u043e BDD \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a \u0434\u043b\u044f \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f javascript \u043a\u043e\u0434\u0430.<\/p>\n<h2>\u041d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435<\/h2>\n<p>\u0412 \u044d\u0442\u043e \u0440\u0430\u0437 \u0443 \u043d\u0430\u0441 \u0442\u0430\u043a\u0436\u0435 \u0435\u0441\u0442\u044c \u043d\u0435\u043a\u043e\u0435 \u0441\u0442\u0430\u0440\u0442\u043e\u0432\u043e\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0441 \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u043c \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u043c Comments \u0438 \u0441\u0435\u0440\u0432\u0438\u0441\u043e\u043c \u0441 \u043e\u0434\u043d\u043e\u0438\u043c\u0435\u043d\u043d\u044b\u043c \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435\u043c. \u0412 \u043a\u043e\u0440\u043d\u0435 \u043d\u0430\u0448\u0435\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u0432\u0441\u0435 \u0442\u0430\u043a\u0436\u0435 \u0435\u0441\u0442\u044c \u043f\u0440\u0435\u0434\u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0439 \u0444\u0430\u0439\u043b karma.conf.js (\u0441\u043e\u0437\u0434\u0430\u0435\u0442\u0441\u044f \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043f\u0440\u0438 \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0447\u0435\u0440\u0435\u0437 Angular CLI). \u0412 \u043d\u0435\u043c \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u043a\u043e\u043d\u0444\u0438\u0433 \u043d\u0430\u0448\u0435\u0433\u043e \u0442\u0435\u0441\u0442 \u0440\u0430\u043d\u043d\u0435\u0440\u0430. \u0417\u0434\u0435\u0441\u044c \u0437\u0430\u0434\u0430\u044e\u0442\u0441\u044f \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u0442\u043e\u0433\u043e, \u0432 \u043a\u0430\u043a\u043e\u043c \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0435 \u0431\u0443\u0434\u0435\u0442 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442\u0441\u044f \u043e\u043a\u043d\u043e \u0442\u0435\u0441\u0442 \u0440\u0430\u043d\u043d\u0435\u0440\u0430 (\u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0441\u0442\u043e\u0438\u0442 Chrome), \u043a\u0430\u043a\u0438\u0435 \u043f\u043b\u0430\u0433\u0438\u043d\u044b \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0442\u044c, \u0438 \u043d\u0430 \u043a\u0430\u043a\u043e\u043c \u043f\u043e\u0440\u0442\u0443 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u0442\u0435\u0441\u0442 \u0440\u0430\u043d\u043d\u0435\u0440 (\u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u043f\u043e\u0440\u0442 9876). \u0412 <code>src\/app<\/code> \u043b\u0435\u0436\u0438\u0442 \u043d\u0430\u0448 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 Comments, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<pre><code class=\"javascript\">import { Component, OnInit } from '@angular\/core'; import { CommentsService } from '..\/shared\/comments.service';  @Component({   selector: 'app-comments',   templateUrl: '.\/comments.component.html',   styleUrls: ['.\/comments.component.scss'] }) export class CommentsComponent implements OnInit {   comments: any[] = [];      constructor(private service: CommentsService) {}    ngOnInit(): void {     this.service.getComments().subscribe(c => {       this.comments = c;     });   }      add(text: string) {     const comment = {text};     this.service.create(comment).subscribe( c => {       this.comments.push(c);     }, err => this.message = err);   } }<\/code><\/pre>\n<p>\u041d\u0430\u0448 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 &#171;\u0438\u043d\u0436\u0435\u043a\u0442\u0438\u0440\u0443\u0435\u0442&#187; \u0432 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440, \u0441\u0435\u0440\u0432\u0438\u0441 <code>CommentService<\/code> \u0430 \u0442\u0430\u043a\u0436\u0435 \u0441\u043e\u0437\u0434\u0430\u0435\u0442 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e <code>comments<\/code> \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043c\u0430\u0441\u0441\u0438\u0432\u043e\u043c \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0443\u0442 \u043f\u043e\u043c\u0435\u0449\u0430\u0442\u044c\u0441\u044f \u0432\u0441\u0435 \u043d\u0430\u0448\u0438 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0438. \u041f\u0440\u0438 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430, \u0432 \u0448\u0430\u0433\u0435 <code>ngOnInit<\/code> \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0438\u0437 \u0441\u0435\u0440\u0432\u0438\u0441\u0430, \u043c\u0435\u0442\u043e\u0434 <code>getComments<\/code>, \u043d\u0430 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043c\u044b \u043f\u043e\u0434\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0438 \u043a\u043b\u0430\u0434\u0435\u043c \u0432 <code>comments<\/code>, \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432\u044b\u0437\u043e\u0432\u0430.<br \/>\u0422\u0430\u043a \u0436\u0435 \u043f\u0440\u0438\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u043c\u0435\u0442\u043e\u0434 <code>add<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0432 \u0441\u0435\u0431\u044f \u0442\u0435\u043a\u0441\u0442 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f \u0438 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 \u0432\u043d\u0443\u0442\u0440\u0438 \u0441\u0435\u0431\u044f \u043c\u0435\u0442\u043e\u0434 <code>create<\/code> \u0438\u0437 \u0441\u0435\u0440\u0432\u0438\u0441\u0430, \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0441\u043e\u0437\u0434\u0430\u0435\u0442 \u043d\u043e\u0432\u044b\u0439 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0439 \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u0442 \u0435\u0433\u043e \u0432 \u043c\u0430\u0441\u0441\u0438\u0432 <code>comments<\/code>.<\/p>\n<p>\u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0441\u0435\u0440\u0432\u0438\u0441 <code>CommentsService<\/code> \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043b\u0435\u0436\u0438\u0442 \u0432 \u043f\u0430\u043f\u043a\u0435 shared:<\/p>\n<pre><code class=\"javascript\">import { Injectable } from '@angular\/core'; import {HttpClient} from '@angular\/common\/http'; import { Observable } from 'rxjs';  @Injectable({   providedIn: 'root' }) export class CommentsService {    constructor(private http: HttpClient) {}    create(comment: any): Observable&lt;any> {     return this.http.post(``, comment);   }    getComments(): Observable&lt;any[]> {     return this.http.get&lt;any[]>(``);   } }<\/code><\/pre>\n<p>\u0421\u0435\u0440\u0432\u0438\u0441 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0432 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440, <code>HttpClient<\/code> \u0438 \u0438\u043c\u0435\u0435\u0442 \u0434\u0432\u0430 \u043c\u0435\u0442\u043e\u0434\u0430 <code>create<\/code> \u0438 <code>getComments<\/code> \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u044e\u0442 POST \u0438 GET \u0437\u0430\u043f\u0440\u043e\u0441\u044b. \u0417\u0430\u043f\u0440\u043e\u0441\u044b \u0438\u043c\u0435\u044e\u0442 \u043f\u0443\u0441\u0442\u043e\u0435 \u043f\u043e\u043b\u0435 <code>url<\/code> \u0442\u0430\u043a \u043a\u0430\u043a \u043f\u043e \u0441\u0443\u0442\u0438 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f &#171;\u043c\u043e\u043a\u043e\u0432\u044b\u043c\u0438&#187; \u0438 \u043d\u0430\u0448\u0435 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043d\u0435 \u0432\u044b\u0445\u043e\u0434\u0438\u0442 \u0437\u0430 \u0440\u0430\u043c\u043a\u0438 \u043a\u043b\u0430\u0441\u0441\u043e\u0432.<\/p>\n<h3>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 spec \u0444\u0430\u0439\u043b\u0430<\/h3>\n<p>\u0421 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u043c \u0438 \u0441\u0435\u0440\u0432\u0438\u0441\u043e\u043c \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u043b\u0438\u0441\u044c \u0442\u0435\u043f\u0435\u0440\u044c \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0444\u0430\u0439\u043b <code>comments.component.spec.ts<\/code> \u0432 \u043f\u0430\u043f\u043a\u0435 \u0441 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u043c \u0438 \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0432 \u043d\u0435\u0433\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0435:<\/p>\n<pre><code class=\"javascript\">import { CommentsComponent } from '.\/comments.component'; import { CommentsService } from '..\/shared\/comments.service';  describe('CommentsComponent', () => {   let component: CommentsComponent;   let service: CommentsService;  });<\/code><\/pre>\n<p>\u0422\u0443\u0442 \u043c\u044b \u044d\u043a\u0441\u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043b\u0438 \u043d\u0430\u0448 \u0442\u0435\u0441\u0442\u0438\u0440\u0443\u0435\u043c\u044b\u0439 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 <code>CommentsComponent<\/code> \u0438 \u0441\u0435\u0440\u0432\u0438\u0441 <code>CommentsService<\/code>, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0439 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u043d\u0430\u0448\u0435\u0433\u043e \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430. \u0422\u0430\u043a\u0436\u0435 \u0434\u043e\u0431\u0430\u0432\u0438\u043b\u0438 \u043e\u0431\u0435\u0440\u0442\u043a\u0443 <code>describe<\/code> \u0434\u043b\u044f \u043d\u0430\u0448\u0435\u0433\u043e \u0442\u0435\u0441\u0442\u043e\u0432\u043e\u0433\u043e \u043d\u0430\u0431\u043e\u0440\u0430 \u0438 \u0442\u0430\u043a\u0436\u0435 \u043e\u0431\u044a\u044f\u0432\u0438\u043b\u0438 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 <code>component<\/code>  \u0438 <code>service<\/code> \u0434\u043b\u044f \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430 \u0438 \u0441\u0435\u0440\u0432\u0438\u0441\u0430 \u0432 \u0442\u0435\u0441\u0442\u0430\u0445.<\/p>\n<p>\u0417\u0430\u043f\u0443\u0441\u0442\u0438\u043c Karma \u043a\u043e\u043c\u0430\u043d\u0434\u043e\u0439 <code>ng test<\/code>. \u041e\u0442\u043a\u0440\u043e\u0435\u0442\u0441\u044f \u043e\u043a\u043d\u043e \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0430 \u0441 \u043e\u0442\u043a\u0440\u044b\u0442\u044b\u043c \u0442\u0435\u0441\u0442 \u0440\u0430\u043d\u043d\u0435\u0440\u043e\u043c \u043d\u0430 \u043f\u043e\u0440\u0442\u0435 9876.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/5dc\/1c1\/f1c\/5dc1c1f1c2c56e3e2062da0bfdcad2e7.png\" width=\"984\" height=\"265\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/5dc\/1c1\/f1c\/5dc1c1f1c2c56e3e2062da0bfdcad2e7.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u041e\u0442\u0447\u0435\u0442 \u043f\u0443\u0441\u0442\u043e\u0439, \u0442\u0430\u043a \u043a\u0430\u043a \u043c\u044b \u0435\u0449\u0435 \u043d\u0435 \u0434\u043e\u0431\u0430\u0432\u0438\u043b\u0438 \u043d\u0438 \u043e\u0434\u043d\u043e\u0433\u043e \u0442\u0435\u0441\u0442\u0430. \u041f\u0440\u0438\u0441\u0442\u0443\u043f\u0438\u043c \u043a \u0438\u0445 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044e.<\/p>\n<h3>\u0414\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0442\u0435\u0441\u0442\u043e\u0432<\/h3>\n<p>\u041e\u0442\u043a\u0440\u044b\u0432\u0430\u0435\u043c \u043d\u0430\u0448 \u0444\u0430\u0439\u043b <code>comments.component.spec.ts<\/code>  \u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044e <code>beforeEach<\/code> \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043f\u0440\u043e\u043f\u0438\u0448\u0435\u043c \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u043d\u0430\u0448\u0435\u0433\u043e \u0441\u0435\u0440\u0432\u0438\u0441\u0430 \u0438 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430, \u043f\u0440\u0438 \u043a\u0430\u0436\u0434\u043e\u043c \u0437\u0430\u043f\u0443\u0441\u043a\u0435 \u0442\u0435\u0441\u0442\u0430, \u0447\u0442\u043e \u0441\u043e\u0437\u0434\u0430\u0441\u0442 \u0438\u0437\u043e\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0441\u0442\u044c \u0434\u043b\u044f \u043d\u0430\u0448\u0438\u0445 \u0442\u0435\u0441\u0442\u043e\u0432. \u0422\u0430\u043a\u0436\u0435 \u0441\u0435\u0440\u0432\u0438\u0441\u0443 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c <code>HttpClient<\/code> \u0442\u0430\u043a \u043a\u0430\u043a \u043e\u043d \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0435\u0433\u043e \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430. \u0422\u0430\u043a \u043a\u0430\u043a \u043d\u0430\u043c  \u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u0434\u0435\u043b\u0430\u0442\u044c \u0444\u0438\u0437\u0438\u0447\u0435\u0441\u043a\u0438\u0435 http-\u0437\u0430\u043f\u0440\u043e\u0441\u044b (\u043c\u044b \u0442\u0435\u0441\u0442\u0438\u0440\u0443\u0435\u043c \u0442\u043e\u043b\u044c\u043a\u043e \u043a\u043e\u0434, \u0430 \u043d\u0435 api), \u043c\u044b \u0441\u0434\u0435\u043b\u0430\u0435\u043c &#171;\u0448\u043f\u0438\u043e\u043d\u0430&#187; \u0434\u043b\u044f <code>HttpClient<\/code>, \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043c\u0435\u0442\u043e\u0434\u0430 <code>createSpyObj<\/code> \u0432 Jasmine, \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0434\u0438\u043c \u0435\u0433\u043e \u0441\u0435\u0440\u0432\u0438\u0441\u0443.<\/p>\n<pre><code class=\"javascript\">import { CommentsComponent } from '.\/comments.component'; import { CommentsService } from '..\/shared\/comments.service';  describe('CommentsComponent', () => {   let component: CommentsComponent;   let service: CommentsService;      beforeEach(() => {     const spyHttp = jasmine.createSpyObj('HttpClient', { post: of({}), get: of({}) })     service = new CommentsService(spyHttp);     component = new CommentsComponent(service);   });    });<\/code><\/pre>\n<p>\u0414\u0430\u043b\u0435\u0435 \u0447\u0435\u0440\u0435\u0437 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044e <code>it<\/code> \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0442\u0435\u0441\u0442 \u043d\u0430 \u0442\u043e \u0447\u0442\u043e \u043d\u0430\u0448 \u0432 \u043d\u0430\u0448\u0435\u043c \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0435 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043c\u0435\u0442\u043e\u0434 <code>getComments<\/code> \u0432 \u043c\u043e\u043c\u0435\u043d\u0442 \u0435\u0433\u043e \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 (ngOnInit):<\/p>\n<pre><code class=\"javascript\">import { CommentsService } from '..\/shared\/comments.service'; import { of, EMPTY } from 'rxjs' import { CommentsComponent } from '.\/comments.component';  describe('CommentsComponent', () => {   let component: CommentsComponent;   let service: CommentsService;    beforeEach(() => {     const spyHttp = jasmine.createSpyObj('HttpClient', { post: of({}), get: of({}) })     service = new CommentsService(spyHttp);     component = new CommentsComponent(service);   });    it('should call getComments when ngOnInit', () => {     const spy = spyOn(service, 'getComments').and.callFake(() => {     return EMPTY;   });    component.ngOnInit();   expect(spy).toHaveBeenCalled();   }); });<\/code><\/pre>\n<p>\u0422\u0443\u0442 \u043c\u044b &#171;\u0437\u0430\u043c\u043e\u043a\u0430\u043b\u0438&#187; \u043c\u0435\u0442\u043e\u0434 <code>getComments<\/code> (\u0442.\u0435. \u0441\u043b\u0435\u0434\u0438\u043c \u0437\u0430 \u0432\u044b\u0437\u043e\u0432\u043e\u043c \u044d\u0442\u043e\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430), \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043c\u0435\u0442\u043e\u0434\u0430 <code>spyOn<\/code> \u0438 \u043f\u043e\u043b\u043e\u0436\u0438\u043b\u0438 \u0432\u0441\u0435 \u0432 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e <code>spy<\/code>. \u0415\u0441\u043b\u0438 \u043c\u044b \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 <code>getComments<\/code> \u0442\u043e \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u043e\u0448\u0438\u0431\u043a\u0443 \u0442\u0430\u043a \u043a\u0430\u043a url \u0443 \u043d\u0430\u0441 \u043f\u0443\u0441\u0442\u043e\u0439. \u0421\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u044d\u0442\u043e \u043d\u0430\u043c \u0438 \u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u0442\u0430\u043a \u043a\u0430\u043a \u043c\u044b \u043d\u0435 \u0442\u0435\u0441\u0442\u0438\u0440\u0443\u0435\u043c api \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435. <\/p>\n<p>\u0423\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0432 &#171;\u0441\u043b\u0435\u0436\u043a\u0443&#187; \u0437\u0430 \u043c\u0435\u0442\u043e\u0434\u043e\u043c, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0438\u043c \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043c\u044b \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u043c\u0435\u0442\u043e\u0434 <code>callFake<\/code> \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u043c \u043a\u043e\u043b\u0431\u0435\u043a. \u041a\u043e\u043b\u0431\u0435\u043a \u0434\u043e\u043b\u0436\u0435\u043d \u043d\u0430\u043c \u0432\u0435\u0440\u043d\u0443\u0442\u044c \u043a\u0430\u043a\u043e\u0439 \u043b\u0438\u0431\u043e  <code>observable<\/code>, \u0441\u043e\u0433\u043b\u0430\u0441\u043d\u043e \u043d\u0430\u0448\u0435\u043c\u0443 \u043c\u0435\u0442\u043e\u0434\u0443 <code>getComments<\/code>. \u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043d\u0430\u043c \u043d\u0435 \u0432\u0430\u0436\u043d\u043e \u0447\u0442\u043e \u043e\u043d \u0431\u0443\u0434\u0435\u0442 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432 <code>return<\/code> \u0441\u0442\u0430\u0432\u0438\u043c \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u0443 <code>EMPTY<\/code> \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u0438\u0437 <code>rxjs<\/code>.<\/p>\n<p>\u0417\u0430\u0442\u0435\u043c \u043c\u044b \u043e\u0431\u0440\u0430\u0449\u0430\u0435\u043c\u0441\u044f \u043a \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0443 \u0438 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u0443 \u043d\u0435\u0433\u043e \u043c\u0435\u0442\u043e\u0434 <code>ngOnInit<\/code>. \u0414\u0430\u043b\u0435\u0435 \u0441\u0442\u0430\u0432\u0438\u043c \u043e\u0436\u0438\u0434\u0430\u043d\u0438\u0435 \u0442\u043e\u0433\u043e \u0447\u0442\u043e \u043d\u0430\u0448 <code>spy<\/code> (\u0442\u0430\u043c \u043d\u0430\u0448 \u0437\u0430\u043c\u043e\u043a\u0430\u043d\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 <code>getComments<\/code>) \u0431\u044b\u043b \u0432\u044b\u0437\u0432\u0430\u043d, \u043f\u0440\u0438 \u0432\u044b\u0437\u043e\u0432\u0435 \u043c\u0435\u0442\u043e\u0434\u0430 <code>ngOnInit<\/code> \u0432 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0435, \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u044f \u044d\u0442\u043e \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043c\u0435\u0442\u043e\u0434\u0430 <code>toHaveBeenCalled<\/code>.<\/p>\n<p>\u041f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u043e\u043a\u043d\u043e \u0442\u0435\u0441\u0442 \u0440\u0430\u043d\u043d\u0435\u0440\u0430 \u0438 \u043d\u0430\u0448 \u0442\u0435\u0441\u0442 \u0434\u043e\u043b\u0436\u0435\u043d \u043f\u043e\u044f\u0432\u0438\u0442\u0441\u044f \u0432 \u043e\u0442\u0447\u0435\u0442\u0435 \u0441 \u0443\u0441\u043f\u0435\u0448\u043d\u044b\u043c \u0441\u0442\u0430\u0442\u0443\u0441\u043e\u043c.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/d5c\/bbf\/dd9\/d5cbbfdd93afe7463645819e9cc969e9.png\" width=\"983\" height=\"256\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/d5c\/bbf\/dd9\/d5cbbfdd93afe7463645819e9cc969e9.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0432\u0442\u043e\u0440\u043e\u0439 \u0442\u0435\u0441\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442 \u0447\u0442\u043e \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 <code>comments<\/code>, \u0432 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0435, \u043f\u0440\u0438\u0441\u0432\u043e\u0438\u043b\u0438\u0441\u044c \u043a\u0430\u043a\u0438\u0435 \u043b\u0438\u0431\u043e \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 \u043c\u043e\u043c\u0435\u043d\u0442 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043a\u043e\u0434:<\/p>\n<pre><code class=\"javascript\">describe('CommentsComponent', () => {   let component: CommentsComponent;   let service: CommentsService;    beforeEach(() => {     const spyHttp = jasmine.createSpyObj('HttpClient', { post: of({}), get: of({}) })     service = new CommentsService(spyHttp);     component = new CommentsComponent(service);   });    it('should call getComments when ngOnInit', () => {     const spy = spyOn(service, 'getComments').and.callFake(() => {       return EMPTY;     });      component.ngOnInit();      expect(spy).toHaveBeenCalled();   });    it('should update comment length after ngOnInit', () => {     const testComments = [1, 2, 3, 4]     spyOn(service, 'getComments').and.returnValue(of(testComments))      component.ngOnInit();      expect(component.comments.length).toBe(testComments.length);   });  });<\/code><\/pre>\n<p>\u0412\u043e \u0432\u0442\u043e\u0440\u043e\u043c \u0442\u0435\u0441\u0442\u0435, \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u043b\u0438 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e <code>testComments<\/code> \u0441 \u043c\u0430\u0441\u0441\u0438\u0432\u043e\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439. \u0422\u0430\u043a \u0436\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u043c\u0435\u0442\u043e\u0434 <code>spyOn<\/code> \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u043c <code>getComments<\/code> \u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043c\u0435\u0442\u043e\u0434 <code>returnValue<\/code> \u0442\u0430\u043a \u043a\u0430\u043a \u0442\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c \u0443\u0436\u0435 \u043d\u0435 \u043f\u0443\u0441\u0442\u043e\u0439 <code>observable<\/code>, \u0430 \u0441 \u043c\u0430\u0441\u0441\u0438\u0432\u043e\u043c <code>comments<\/code>. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u043c\u0435\u0442\u043e\u0434 <code>of<\/code> \u0438\u0437 <code>rxjs<\/code>.<\/p>\n<p>\u0417\u0430\u0442\u0435\u043c \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e \u043e\u0431\u0440\u0430\u0449\u0430\u0435\u043c\u0441\u044f \u043a \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0443 \u0438 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u0443 \u043d\u0435\u0433\u043e \u043c\u0435\u0442\u043e\u0434 <code>ngOnInit<\/code>. \u0414\u0430\u043b\u0435\u0435 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043e\u0436\u0438\u0434\u0430\u043d\u0438\u0435 \u0442\u043e\u0433\u043e \u0447\u0442\u043e \u043d\u0430\u0448\u0430 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f <code>comments<\/code> \u0432 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0430 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0438\u0437 <code>testComments<\/code> \u043f\u0440\u0438 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430. \u0421\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u043d\u0430\u0448 \u043c\u0435\u0442\u043e\u0434 <code>getComments<\/code> \u043e\u0442\u0440\u0430\u0431\u043e\u0442\u0430\u043b \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e.<\/p>\n<p>\u041f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u0442\u0435\u0441\u0442 \u0440\u0430\u043d\u043d\u0435\u0440 \u0438 \u0432\u0438\u0434\u0438\u043c \u0447\u0442\u043e \u0432\u0442\u043e\u0440\u043e\u0439 \u0442\u0435\u0441\u0442 \u0443\u0441\u043f\u0435\u0448\u043d\u043e \u043f\u0440\u043e\u0439\u0434\u0435\u043d.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/106\/28f\/46b\/10628f46b545d81d8d62c996736925d2.png\" width=\"976\" height=\"246\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/106\/28f\/46b\/10628f46b545d81d8d62c996736925d2.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u041d\u0443 \u0438 \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0442\u0435\u043f\u0435\u0440\u044c \u0442\u0435\u0441\u0442 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f.<\/p>\n<pre><code class=\"javascript\">import { CommentsService } from '..\/shared\/comments.service'; import { of, EMPTY, throwError } from 'rxjs' import { CommentsComponent } from '.\/comments.component';  describe('CommentsComponent', () => {   let component: CommentsComponent;   let service: CommentsService;    beforeEach(() => {     const spyHttp = jasmine.createSpyObj('HttpClient', { post: of({}), get: of({}) })     service = new CommentsService(spyHttp);     component = new CommentsComponent(service);   });    it('should call getComments when ngOnInit', () => {     const spy = spyOn(service, 'getComments').and.callFake(() => {       return EMPTY;     });      component.ngOnInit();      expect(spy).toHaveBeenCalled();   });    it('should update comment length after ngOnInit', () => {     const testComments = [1, 2, 3, 4]     spyOn(service, 'getComments').and.returnValue(of(testComments))      component.ngOnInit();      expect(component.comments.length).toBe(testComments.length);   });    it('should add new comment', () => {     const testComment = {text: 'test'}     const spy = spyOn(service, 'create').and.returnValue(of(testComment))      component.add(testComment.text)      expect(spy).toHaveBeenCalled()     expect(component.comments.includes(testComment)).toBeTruthy()   });  });<\/code><\/pre>\n<p>\u0422\u0443\u0442 \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u043b\u0438 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e <code>testComment<\/code> \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0432 \u0441\u0435\u0431\u0435 \u043e\u0431\u044a\u0435\u043a\u0442 \u043d\u0430\u0448\u0435\u0433\u043e \u0442\u0435\u0441\u0442\u043e\u0432\u043e\u0433\u043e \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f. \u0414\u0430\u043b\u0435\u0435 \u043c\u044b \u0442\u0435\u043f\u0435\u0440\u044c \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e &#171;\u0437\u0430\u043c\u043e\u043a\u0430\u043b\u0438&#187; \u043c\u0435\u0442\u043e\u0434 <code>create<\/code>, \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043c\u0435\u0442\u043e\u0434\u0430 <code>spyOn<\/code> \u0438 \u0434\u043e\u0431\u0430\u0432\u0438\u043b\u0438 \u043c\u0435\u0442\u043e\u0434 <code>returnValue<\/code> \u0442\u0430\u043a \u043a\u0430\u043a \u0443 \u043d\u0430\u0441 \u0437\u0434\u0435\u0441\u044c \u0431\u0443\u0434\u0435\u0442 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c\u0441\u044f \u043d\u0435 \u043f\u0443\u0441\u0442\u043e\u0439 <code>observable<\/code> \u0430 \u043d\u0430\u0448 \u0442\u0435\u0441\u0442\u043e\u0432\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 <code>testComment<\/code>, \u0438 \u0442\u0430\u043a\u0436\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0438 \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043c\u0435\u0442\u043e\u0434 <code>of<\/code> \u0438\u0437 <code>rxjs<\/code>. \u0417\u0430\u0442\u0435\u043c \u043f\u043e\u043b\u043e\u0436\u0438\u043b\u0438 \u0432\u0441\u0435 \u044d\u0442\u043e \u0432 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e <code>spy.<br \/><\/code><br \/>\u0414\u0430\u043b\u0435\u0435 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043c\u0435\u0442\u043e\u0434 <code>add<\/code> \u043d\u0430\u0448\u0435\u0433\u043e \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430, \u043a \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u0442\u0441\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043a\u043b\u044e\u0447\u0430 text \u043d\u0430\u0448\u0435\u0433\u043e \u0442\u0435\u0441\u0442\u043e\u0432\u043e\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0441 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0435\u043c (testObject). \u041f\u043e\u0441\u043b\u0435 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u043e\u0436\u0438\u0434\u0430\u043d\u0438\u0435 \u0442\u043e\u0433\u043e \u0447\u0442\u043e <code>spy<\/code> (\u0442\u0430\u043c \u043d\u0430\u0448 \u0437\u0430\u043c\u043e\u043a\u0430\u043d\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 <code>create<\/code> \u0438\u0437 \u0441\u0435\u0440\u0432\u0438\u0441\u0430) \u0431\u044b\u043b \u0432\u044b\u0437\u0432\u0430\u043d \u043f\u0440\u0438 \u0432\u044b\u0437\u043e\u0432\u0435 \u043c\u0435\u0442\u043e\u0434\u0430 <code>add<\/code> \u0432 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0435. \u0417\u0430\u0442\u0435\u043c \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u0447\u0442\u043e \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f \u0441 \u043c\u0430\u0441\u0441\u0438\u0432\u043e\u043c <code>comments<\/code>, \u0432 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0435, \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0430 \u043d\u0430\u0448 \u0442\u0435\u0441\u0442\u043e\u0432\u044b\u0439 \u043a\u043e\u043c\u043c\u0435\u043d\u0442 (\u043c\u0435\u0442\u043e\u0434\u044b <code>includes<\/code> \u0438 <code>toBeTruthy<\/code>). <\/p>\n<p>\u0421\u043d\u043e\u0432\u0430 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u0442\u0435\u0441\u0442 \u0440\u0430\u043d\u043d\u0435\u0440 \u0438 \u0432\u0438\u0434\u0438\u043c \u0447\u0442\u043e \u0442\u0435\u0441\u0442 \u043f\u0440\u043e\u0448\u0435\u043b \u043a\u0430\u043a \u0438 \u0432\u0441\u0435 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/2f1\/18a\/d80\/2f118ad8000924995e515f097712e9eb.png\" width=\"983\" height=\"260\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/2f1\/18a\/d80\/2f118ad8000924995e515f097712e9eb.png\"\/><figcaption><\/figcaption><\/figure>\n<h2>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h2>\n<p>\u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043c\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043b\u0438 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430 \u0441 \u0441\u0435\u0440\u0432\u0438\u0441\u043e\u043c. \u041f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c \u0441\u043b\u0435\u0433\u043a\u0430 \u0437\u0430\u043f\u0443\u0442\u0430\u043d\u043e \u0438 \u0431\u0435\u0437 \u0431\u0430\u0437\u043e\u0432\u043e\u0433\u043e \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u044f rxjs, \u0431\u0443\u0434\u0435\u0442 \u0441\u043b\u043e\u0436\u043d\u043e\u0432\u0430\u0442\u043e \u043f\u043e\u043d\u044f\u0442\u044c \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u044f\u0449\u0435\u0435.<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/593501\/\"> https:\/\/habr.com\/ru\/articles\/593501\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u0412 \u043f\u0440\u043e\u0448\u043b\u043e\u0439 <a href=\"https:\/\/habr.com\/ru\/post\/575644\/\" rel=\"noopener noreferrer nofollow\">\u0441\u0442\u0430\u0442\u044c\u0435<\/a>, \u044f \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u043b \u043a\u0430\u043a \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442. \u0422\u0435\u043f\u0435\u0440\u044c \u0436\u0435 \u043a\u043e\u0441\u043d\u0435\u043c\u0441\u044f \u0432\u043e\u043f\u0440\u043e\u0441\u0430 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0441\u0435\u0440\u0432\u0438\u0441\u0430. <\/p>\n<h2>\u0412\u0441\u0442\u0443\u043f\u043b\u0435\u043d\u0438\u0435<\/h2>\n<p>\u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0442\u0430\u043a \u0436\u0435, \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u044b \u0438\u0434\u0443\u0449\u0438\u0435 \u0438\u0437 &#171;\u043a\u043e\u0440\u043e\u0431\u043a\u0438&#187;, \u0442\u0430\u043a\u0438\u0435 \u043a\u0430\u043a Karma \u0438 Jasmine. <\/p>\n<p>\u0412\u043a\u0440\u0430\u0442\u0446\u0435 \u043f\u043e\u0432\u0442\u043e\u0440\u044e \u0447\u0442\u043e \u044d\u0442\u043e \u0437\u0430 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u044b: Karma \u044d\u0442\u043e \u0442\u0430\u043a \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u043c\u044b\u0439 \u0442\u0435\u0441\u0442 \u0440\u0430\u043d\u043d\u0435\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043d\u0430\u043c \u043d\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0442\u044c \u0442\u043e \u043d\u0430 \u043a\u0430\u043a\u0438\u0445 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430\u0445 \u0438\u043b\u0438 \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0430\u0445 \u0431\u0443\u0434\u0443\u0442 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c\u0441\u044f \u0442\u0435\u0441\u0442\u044b \u0438 \u043a\u0430\u043a\u0438\u0435 \u0442\u0435\u0441\u0442\u043e\u0432\u044b\u0435 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0438 \u0438 \u043f\u043b\u0430\u0433\u0438\u043d\u044b, \u0431\u0443\u0434\u0443\u0442 \u0443\u0447\u0430\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0432 \u0442\u0435\u0441\u0442\u0430\u0445. Jasmine \u044d\u0442\u043e BDD \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a \u0434\u043b\u044f \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f javascript \u043a\u043e\u0434\u0430.<\/p>\n<h2>\u041d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435<\/h2>\n<p>\u0412 \u044d\u0442\u043e \u0440\u0430\u0437 \u0443 \u043d\u0430\u0441 \u0442\u0430\u043a\u0436\u0435 \u0435\u0441\u0442\u044c \u043d\u0435\u043a\u043e\u0435 \u0441\u0442\u0430\u0440\u0442\u043e\u0432\u043e\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0441 \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u043c \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u043c Comments \u0438 \u0441\u0435\u0440\u0432\u0438\u0441\u043e\u043c \u0441 \u043e\u0434\u043d\u043e\u0438\u043c\u0435\u043d\u043d\u044b\u043c \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435\u043c. \u0412 \u043a\u043e\u0440\u043d\u0435 \u043d\u0430\u0448\u0435\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u0432\u0441\u0435 \u0442\u0430\u043a\u0436\u0435 \u0435\u0441\u0442\u044c \u043f\u0440\u0435\u0434\u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0439 \u0444\u0430\u0439\u043b karma.conf.js (\u0441\u043e\u0437\u0434\u0430\u0435\u0442\u0441\u044f \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043f\u0440\u0438 \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0447\u0435\u0440\u0435\u0437 Angular CLI). \u0412 \u043d\u0435\u043c \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u043a\u043e\u043d\u0444\u0438\u0433 \u043d\u0430\u0448\u0435\u0433\u043e \u0442\u0435\u0441\u0442 \u0440\u0430\u043d\u043d\u0435\u0440\u0430. \u0417\u0434\u0435\u0441\u044c \u0437\u0430\u0434\u0430\u044e\u0442\u0441\u044f \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u0442\u043e\u0433\u043e, \u0432 \u043a\u0430\u043a\u043e\u043c \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0435 \u0431\u0443\u0434\u0435\u0442 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442\u0441\u044f \u043e\u043a\u043d\u043e \u0442\u0435\u0441\u0442 \u0440\u0430\u043d\u043d\u0435\u0440\u0430 (\u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0441\u0442\u043e\u0438\u0442 Chrome), \u043a\u0430\u043a\u0438\u0435 \u043f\u043b\u0430\u0433\u0438\u043d\u044b \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0442\u044c, \u0438 \u043d\u0430 \u043a\u0430\u043a\u043e\u043c \u043f\u043e\u0440\u0442\u0443 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u0442\u0435\u0441\u0442 \u0440\u0430\u043d\u043d\u0435\u0440 (\u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u043f\u043e\u0440\u0442 9876). \u0412 <code>src\/app<\/code> \u043b\u0435\u0436\u0438\u0442 \u043d\u0430\u0448 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 Comments, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<pre><code class=\"javascript\">import { Component, OnInit } from '@angular\/core'; import { CommentsService } from '..\/shared\/comments.service';  @Component({   selector: 'app-comments',   templateUrl: '.\/comments.component.html',   styleUrls: ['.\/comments.component.scss'] }) export class CommentsComponent implements OnInit {   comments: any[] = [];      constructor(private service: CommentsService) {}    ngOnInit(): void {     this.service.getComments().subscribe(c => {       this.comments = c;     });   }      add(text: string) {     const comment = {text};     this.service.create(comment).subscribe( c => {       this.comments.push(c);     }, err => this.message = err);   } }<\/code><\/pre>\n<p>\u041d\u0430\u0448 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 &#171;\u0438\u043d\u0436\u0435\u043a\u0442\u0438\u0440\u0443\u0435\u0442&#187; \u0432 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440, \u0441\u0435\u0440\u0432\u0438\u0441 <code>CommentService<\/code> \u0430 \u0442\u0430\u043a\u0436\u0435 \u0441\u043e\u0437\u0434\u0430\u0435\u0442 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e <code>comments<\/code> \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043c\u0430\u0441\u0441\u0438\u0432\u043e\u043c \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0443\u0442 \u043f\u043e\u043c\u0435\u0449\u0430\u0442\u044c\u0441\u044f \u0432\u0441\u0435 \u043d\u0430\u0448\u0438 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0438. \u041f\u0440\u0438 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430, \u0432 \u0448\u0430\u0433\u0435 <code>ngOnInit<\/code> \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0438\u0437 \u0441\u0435\u0440\u0432\u0438\u0441\u0430, \u043c\u0435\u0442\u043e\u0434 <code>getComments<\/code>, \u043d\u0430 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043c\u044b \u043f\u043e\u0434\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0438 \u043a\u043b\u0430\u0434\u0435\u043c \u0432 <code>comments<\/code>, \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432\u044b\u0437\u043e\u0432\u0430.<br \/>\u0422\u0430\u043a \u0436\u0435 \u043f\u0440\u0438\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u043c\u0435\u0442\u043e\u0434 <code>add<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0432 \u0441\u0435\u0431\u044f \u0442\u0435\u043a\u0441\u0442 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f \u0438 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 \u0432\u043d\u0443\u0442\u0440\u0438 \u0441\u0435\u0431\u044f \u043c\u0435\u0442\u043e\u0434 <code>create<\/code> \u0438\u0437 \u0441\u0435\u0440\u0432\u0438\u0441\u0430, \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0441\u043e\u0437\u0434\u0430\u0435\u0442 \u043d\u043e\u0432\u044b\u0439 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0439 \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u0442 \u0435\u0433\u043e \u0432 \u043c\u0430\u0441\u0441\u0438\u0432 <code>comments<\/code>.<\/p>\n<p>\u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0441\u0435\u0440\u0432\u0438\u0441 <code>CommentsService<\/code> \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043b\u0435\u0436\u0438\u0442 \u0432 \u043f\u0430\u043f\u043a\u0435 shared:<\/p>\n<pre><code class=\"javascript\">import { Injectable } from '@angular\/core'; import {HttpClient} from '@angular\/common\/http'; import { Observable } from 'rxjs';  @Injectable({   providedIn: 'root' }) export class CommentsService {    constructor(private http: HttpClient) {}    create(comment: any): Observable&lt;any> {     return this.http.post(``, comment);   }    getComments(): Observable&lt;any[]> {     return this.http.get&lt;any[]>(``);   } }<\/code><\/pre>\n<p>\u0421\u0435\u0440\u0432\u0438\u0441 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0432 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440, <code>HttpClient<\/code> \u0438 \u0438\u043c\u0435\u0435\u0442 \u0434\u0432\u0430 \u043c\u0435\u0442\u043e\u0434\u0430 <code>create<\/code> \u0438 <code>getComments<\/code> \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u044e\u0442 POST \u0438 GET \u0437\u0430\u043f\u0440\u043e\u0441\u044b. \u0417\u0430\u043f\u0440\u043e\u0441\u044b \u0438\u043c\u0435\u044e\u0442 \u043f\u0443\u0441\u0442\u043e\u0435 \u043f\u043e\u043b\u0435 <code>url<\/code> \u0442\u0430\u043a \u043a\u0430\u043a \u043f\u043e \u0441\u0443\u0442\u0438 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f &#171;\u043c\u043e\u043a\u043e\u0432\u044b\u043c\u0438&#187; \u0438 \u043d\u0430\u0448\u0435 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043d\u0435 \u0432\u044b\u0445\u043e\u0434\u0438\u0442 \u0437\u0430 \u0440\u0430\u043c\u043a\u0438 \u043a\u043b\u0430\u0441\u0441\u043e\u0432.<\/p>\n<h3>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 spec \u0444\u0430\u0439\u043b\u0430<\/h3>\n<p>\u0421 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u043c \u0438 \u0441\u0435\u0440\u0432\u0438\u0441\u043e\u043c \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u043b\u0438\u0441\u044c \u0442\u0435\u043f\u0435\u0440\u044c \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0444\u0430\u0439\u043b <code>comments.component.spec.ts<\/code> \u0432 \u043f\u0430\u043f\u043a\u0435 \u0441 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u043c \u0438 \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0432 \u043d\u0435\u0433\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0435:<\/p>\n<pre><code class=\"javascript\">import { CommentsComponent } from '.\/comments.component'; import { CommentsService } from '..\/shared\/comments.service';  describe('CommentsComponent', () => {   let component: CommentsComponent;   let service: CommentsService;  });<\/code><\/pre>\n<p>\u0422\u0443\u0442 \u043c\u044b \u044d\u043a\u0441\u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043b\u0438 \u043d\u0430\u0448 \u0442\u0435\u0441\u0442\u0438\u0440\u0443\u0435\u043c\u044b\u0439 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 <code>CommentsComponent<\/code> \u0438 \u0441\u0435\u0440\u0432\u0438\u0441 <code>CommentsService<\/code>, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0439 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u043d\u0430\u0448\u0435\u0433\u043e \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430. \u0422\u0430\u043a\u0436\u0435 \u0434\u043e\u0431\u0430\u0432\u0438\u043b\u0438 \u043e\u0431\u0435\u0440\u0442\u043a\u0443 <code>describe<\/code> \u0434\u043b\u044f \u043d\u0430\u0448\u0435\u0433\u043e \u0442\u0435\u0441\u0442\u043e\u0432\u043e\u0433\u043e \u043d\u0430\u0431\u043e\u0440\u0430 \u0438 \u0442\u0430\u043a\u0436\u0435 \u043e\u0431\u044a\u044f\u0432\u0438\u043b\u0438 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 <code>component<\/code>  \u0438 <code>service<\/code> \u0434\u043b\u044f \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430 \u0438 \u0441\u0435\u0440\u0432\u0438\u0441\u0430 \u0432 \u0442\u0435\u0441\u0442\u0430\u0445.<\/p>\n<p>\u0417\u0430\u043f\u0443\u0441\u0442\u0438\u043c Karma \u043a\u043e\u043c\u0430\u043d\u0434\u043e\u0439 <code>ng test<\/code>. \u041e\u0442\u043a\u0440\u043e\u0435\u0442\u0441\u044f \u043e\u043a\u043d\u043e \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0430 \u0441 \u043e\u0442\u043a\u0440\u044b\u0442\u044b\u043c \u0442\u0435\u0441\u0442 \u0440\u0430\u043d\u043d\u0435\u0440\u043e\u043c \u043d\u0430 \u043f\u043e\u0440\u0442\u0435 9876.<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u041e\u0442\u0447\u0435\u0442 \u043f\u0443\u0441\u0442\u043e\u0439, \u0442\u0430\u043a \u043a\u0430\u043a \u043c\u044b \u0435\u0449\u0435 \u043d\u0435 \u0434\u043e\u0431\u0430\u0432\u0438\u043b\u0438 \u043d\u0438 \u043e\u0434\u043d\u043e\u0433\u043e \u0442\u0435\u0441\u0442\u0430. \u041f\u0440\u0438\u0441\u0442\u0443\u043f\u0438\u043c \u043a \u0438\u0445 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044e.<\/p>\n<h3>\u0414\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0442\u0435\u0441\u0442\u043e\u0432<\/h3>\n<p>\u041e\u0442\u043a\u0440\u044b\u0432\u0430\u0435\u043c \u043d\u0430\u0448 \u0444\u0430\u0439\u043b <code>comments.component.spec.ts<\/code>  \u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044e <code>beforeEach<\/code> \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043f\u0440\u043e\u043f\u0438\u0448\u0435\u043c \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u043d\u0430\u0448\u0435\u0433\u043e \u0441\u0435\u0440\u0432\u0438\u0441\u0430 \u0438 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430, \u043f\u0440\u0438 \u043a\u0430\u0436\u0434\u043e\u043c \u0437\u0430\u043f\u0443\u0441\u043a\u0435 \u0442\u0435\u0441\u0442\u0430, \u0447\u0442\u043e \u0441\u043e\u0437\u0434\u0430\u0441\u0442 \u0438\u0437\u043e\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0441\u0442\u044c \u0434\u043b\u044f \u043d\u0430\u0448\u0438\u0445 \u0442\u0435\u0441\u0442\u043e\u0432. \u0422\u0430\u043a\u0436\u0435 \u0441\u0435\u0440\u0432\u0438\u0441\u0443 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c <code>HttpClient<\/code> \u0442\u0430\u043a \u043a\u0430\u043a \u043e\u043d \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0435\u0433\u043e \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430. \u0422\u0430\u043a \u043a\u0430\u043a \u043d\u0430\u043c  \u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u0434\u0435\u043b\u0430\u0442\u044c \u0444\u0438\u0437\u0438\u0447\u0435\u0441\u043a\u0438\u0435 http-\u0437\u0430\u043f\u0440\u043e\u0441\u044b (\u043c\u044b \u0442\u0435\u0441\u0442\u0438\u0440\u0443\u0435\u043c \u0442\u043e\u043b\u044c\u043a\u043e \u043a\u043e\u0434, \u0430 \u043d\u0435 api), \u043c\u044b \u0441\u0434\u0435\u043b\u0430\u0435\u043c &#171;\u0448\u043f\u0438\u043e\u043d\u0430&#187; \u0434\u043b\u044f <code>HttpClient<\/code>, \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043c\u0435\u0442\u043e\u0434\u0430 <code>createSpyObj<\/code> \u0432 Jasmine, \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0434\u0438\u043c \u0435\u0433\u043e \u0441\u0435\u0440\u0432\u0438\u0441\u0443.<\/p>\n<pre><code class=\"javascript\">import { CommentsComponent } from '.\/comments.component'; import { CommentsService } from '..\/shared\/comments.service';  describe('CommentsComponent', () => {   let component: CommentsComponent;   let service: CommentsService;      beforeEach(() => {     const spyHttp = jasmine.createSpyObj('HttpClient', { post: of({}), get: of({}) })     service = new CommentsService(spyHttp);     component = new CommentsComponent(service);   });    });<\/code><\/pre>\n<p>\u0414\u0430\u043b\u0435\u0435 \u0447\u0435\u0440\u0435\u0437 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044e <code>it<\/code> \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0442\u0435\u0441\u0442 \u043d\u0430 \u0442\u043e \u0447\u0442\u043e \u043d\u0430\u0448 \u0432 \u043d\u0430\u0448\u0435\u043c \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0435 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043c\u0435\u0442\u043e\u0434 <code>getComments<\/code> \u0432 \u043c\u043e\u043c\u0435\u043d\u0442 \u0435\u0433\u043e \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 (ngOnInit):<\/p>\n<pre><code class=\"javascript\">import { CommentsService } from '..\/shared\/comments.service'; import { of, EMPTY } from 'rxjs' import { CommentsComponent } from '.\/comments.component';  describe('CommentsComponent', () => {   let component: CommentsComponent;   let service: CommentsService;    beforeEach(() => {     const spyHttp = jasmine.createSpyObj('HttpClient', { post: of({}), get: of({}) })     service = new CommentsService(spyHttp);     component = new CommentsComponent(service);   });    it('should call getComments when ngOnInit', () => {     const spy = spyOn(service, 'getComments').and.callFake(() => {     return EMPTY;   });    component.ngOnInit();   expect(spy).toHaveBeenCalled();   }); });<\/code><\/pre>\n<p>\u0422\u0443\u0442 \u043c\u044b &#171;\u0437\u0430\u043c\u043e\u043a\u0430\u043b\u0438&#187; \u043c\u0435\u0442\u043e\u0434 <code>getComments<\/code> (\u0442.\u0435. \u0441\u043b\u0435\u0434\u0438\u043c \u0437\u0430 \u0432\u044b\u0437\u043e\u0432\u043e\u043c \u044d\u0442\u043e\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430), \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043c\u0435\u0442\u043e\u0434\u0430 <code>spyOn<\/code> \u0438 \u043f\u043e\u043b\u043e\u0436\u0438\u043b\u0438 \u0432\u0441\u0435 \u0432 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e <code>spy<\/code>. \u0415\u0441\u043b\u0438 \u043c\u044b \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 <code>getComments<\/code> \u0442\u043e \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u043e\u0448\u0438\u0431\u043a\u0443 \u0442\u0430\u043a \u043a\u0430\u043a url \u0443 \u043d\u0430\u0441 \u043f\u0443\u0441\u0442\u043e\u0439. \u0421\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u044d\u0442\u043e \u043d\u0430\u043c \u0438 \u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u0442\u0430\u043a \u043a\u0430\u043a \u043c\u044b \u043d\u0435 \u0442\u0435\u0441\u0442\u0438\u0440\u0443\u0435\u043c api \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435. <\/p>\n<p>\u0423\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0432 &#171;\u0441\u043b\u0435\u0436\u043a\u0443&#187; \u0437\u0430 \u043c\u0435\u0442\u043e\u0434\u043e\u043c, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0438\u043c \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043c\u044b \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u043c\u0435\u0442\u043e\u0434 <code>callFake<\/code> \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u043c \u043a\u043e\u043b\u0431\u0435\u043a. \u041a\u043e\u043b\u0431\u0435\u043a \u0434\u043e\u043b\u0436\u0435\u043d \u043d\u0430\u043c \u0432\u0435\u0440\u043d\u0443\u0442\u044c \u043a\u0430\u043a\u043e\u0439 \u043b\u0438\u0431\u043e  <code>observable<\/code>, \u0441\u043e\u0433\u043b\u0430\u0441\u043d\u043e \u043d\u0430\u0448\u0435\u043c\u0443 \u043c\u0435\u0442\u043e\u0434\u0443 <code>getComments<\/code>. \u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043d\u0430\u043c \u043d\u0435 \u0432\u0430\u0436\u043d\u043e \u0447\u0442\u043e \u043e\u043d \u0431\u0443\u0434\u0435\u0442 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432 <code>return<\/code> \u0441\u0442\u0430\u0432\u0438\u043c \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u0443 <code>EMPTY<\/code> \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u0438\u0437 <code>rxjs<\/code>.<\/p>\n<p>\u0417\u0430\u0442\u0435\u043c \u043c\u044b \u043e\u0431\u0440\u0430\u0449\u0430\u0435\u043c\u0441\u044f \u043a \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0443 \u0438 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u0443 \u043d\u0435\u0433\u043e \u043c\u0435\u0442\u043e\u0434 <code>ngOnInit<\/code>. \u0414\u0430\u043b\u0435\u0435 \u0441\u0442\u0430\u0432\u0438\u043c \u043e\u0436\u0438\u0434\u0430\u043d\u0438\u0435 \u0442\u043e\u0433\u043e \u0447\u0442\u043e \u043d\u0430\u0448 <code>spy<\/code> (\u0442\u0430\u043c \u043d\u0430\u0448 \u0437\u0430\u043c\u043e\u043a\u0430\u043d\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 <code>getComments<\/code>) \u0431\u044b\u043b \u0432\u044b\u0437\u0432\u0430\u043d, \u043f\u0440\u0438 \u0432\u044b\u0437\u043e\u0432\u0435 \u043c\u0435\u0442\u043e\u0434\u0430 <code>ngOnInit<\/code> \u0432 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0435, \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u044f \u044d\u0442\u043e \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043c\u0435\u0442\u043e\u0434\u0430 <code>toHaveBeenCalled<\/code>.<\/p>\n<p>\u041f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u043e\u043a\u043d\u043e \u0442\u0435\u0441\u0442 \u0440\u0430\u043d\u043d\u0435\u0440\u0430 \u0438 \u043d\u0430\u0448 \u0442\u0435\u0441\u0442 \u0434\u043e\u043b\u0436\u0435\u043d \u043f\u043e\u044f\u0432\u0438\u0442\u0441\u044f \u0432 \u043e\u0442\u0447\u0435\u0442\u0435 \u0441 \u0443\u0441\u043f\u0435\u0448\u043d\u044b\u043c \u0441\u0442\u0430\u0442\u0443\u0441\u043e\u043c.<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0432\u0442\u043e\u0440\u043e\u0439 \u0442\u0435\u0441\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442 \u0447\u0442\u043e \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 <code>comments<\/code>, \u0432 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0435, \u043f\u0440\u0438\u0441\u0432\u043e\u0438\u043b\u0438\u0441\u044c \u043a\u0430\u043a\u0438\u0435 \u043b\u0438\u0431\u043e \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 \u043c\u043e\u043c\u0435\u043d\u0442 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043a\u043e\u0434:<\/p>\n<pre><code class=\"javascript\">describe('CommentsComponent', () => {   let component: CommentsComponent;   let service: CommentsService;    beforeEach(() => {     const spyHttp = jasmine.createSpyObj('HttpClient', { post: of({}), get: of({}) })     service = new CommentsService(spyHttp);     component = new CommentsComponent(service);   });    it('should call getComments when ngOnInit', () => {     const spy = spyOn(service, 'getComments').and.callFake(() => {       return EMPTY;     });      component.ngOnInit();      expect(spy).toHaveBeenCalled();   });    it('should update comment length after ngOnInit', () => {     const testComments = [1, 2, 3, 4]     spyOn(service, 'getComments').and.returnValue(of(testComments))      component.ngOnInit();      expect(component.comments.length).toBe(testComments.length);   });  });<\/code><\/pre>\n<p>\u0412\u043e \u0432\u0442\u043e\u0440\u043e\u043c \u0442\u0435\u0441\u0442\u0435, \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u043b\u0438 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e <code>testComments<\/code> \u0441 \u043c\u0430\u0441\u0441\u0438\u0432\u043e\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439. \u0422\u0430\u043a \u0436\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u043c\u0435\u0442\u043e\u0434 <code>spyOn<\/code> \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u043c <code>getComments<\/code> \u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043c\u0435\u0442\u043e\u0434 <code>returnValue<\/code> \u0442\u0430\u043a \u043a\u0430\u043a \u0442\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c \u0443\u0436\u0435 \u043d\u0435 \u043f\u0443\u0441\u0442\u043e\u0439 <code>observable<\/code>, \u0430 \u0441 \u043c\u0430\u0441\u0441\u0438\u0432\u043e\u043c <code>comments<\/code>. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u043c\u0435\u0442\u043e\u0434 <code>of<\/code> \u0438\u0437 <code>rxjs<\/code>.<\/p>\n<p>\u0417\u0430\u0442\u0435\u043c \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e \u043e\u0431\u0440\u0430\u0449\u0430\u0435\u043c\u0441\u044f \u043a \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0443 \u0438 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u0443 \u043d\u0435\u0433\u043e \u043c\u0435\u0442\u043e\u0434 <code>ngOnInit<\/code>. \u0414\u0430\u043b\u0435\u0435 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043e\u0436\u0438\u0434\u0430\u043d\u0438\u0435 \u0442\u043e\u0433\u043e \u0447\u0442\u043e \u043d\u0430\u0448\u0430 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f <code>comments<\/code> \u0432 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0430 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0438\u0437 <code>testComments<\/code> \u043f\u0440\u0438 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430. \u0421\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u043d\u0430\u0448 \u043c\u0435\u0442\u043e\u0434 <code>getComments<\/code> \u043e\u0442\u0440\u0430\u0431\u043e\u0442\u0430\u043b \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e.<\/p>\n<p>\u041f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u0442\u0435\u0441\u0442 \u0440\u0430\u043d\u043d\u0435\u0440 \u0438 \u0432\u0438\u0434\u0438\u043c \u0447\u0442\u043e \u0432\u0442\u043e\u0440\u043e\u0439 \u0442\u0435\u0441\u0442 \u0443\u0441\u043f\u0435\u0448\u043d\u043e \u043f\u0440\u043e\u0439\u0434\u0435\u043d.<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u041d\u0443 \u0438 \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0442\u0435\u043f\u0435\u0440\u044c \u0442\u0435\u0441\u0442 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f.<\/p>\n<pre><code class=\"javascript\">import { CommentsService } from '..\/shared\/comments.service'; import { of, EMPTY, throwError } from 'rxjs' import { CommentsComponent } from '.\/comments.component';  describe('CommentsComponent', () => {   let component: CommentsComponent;   let service: CommentsService;    beforeEach(() => {     const spyHttp = jasmine.createSpyObj('HttpClient', { post: of({}), get: of({}) })     service = new CommentsService(spyHttp);     component = new CommentsComponent(service);   });    it('should call getComments when ngOnInit', () => {     const spy = spyOn(service, 'getComments').and.callFake(() => {       return EMPTY;     });      component.ngOnInit();      expect(spy).toHaveBeenCalled();   });    it('should update comment length after ngOnInit', () => {     const testComments = [1, 2, 3, 4]     spyOn(service, 'getComments').and.returnValue(of(testComments))      component.ngOnInit();      expect(component.comments.length).toBe(testComments.length);   });    it('should add new comment', () => {     const testComment = {text: 'test'}     const spy = spyOn(service, 'create').and.returnValue(of(testComment))      component.add(testComment.text)      expect(spy).toHaveBeenCalled()     expect(component.comments.includes(testComment)).toBeTruthy()   });  });<\/code><\/pre>\n<p>\u0422\u0443\u0442 \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u043b\u0438 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e <code>testComment<\/code> \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0432 \u0441\u0435\u0431\u0435 \u043e\u0431\u044a\u0435\u043a\u0442 \u043d\u0430\u0448\u0435\u0433\u043e \u0442\u0435\u0441\u0442\u043e\u0432\u043e\u0433\u043e \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f. \u0414\u0430\u043b\u0435\u0435 \u043c\u044b \u0442\u0435\u043f\u0435\u0440\u044c \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e &#171;\u0437\u0430\u043c\u043e\u043a\u0430\u043b\u0438&#187; \u043c\u0435\u0442\u043e\u0434 <code>create<\/code>, \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043c\u0435\u0442\u043e\u0434\u0430 <code>spyOn<\/code> \u0438 \u0434\u043e\u0431\u0430\u0432\u0438\u043b\u0438 \u043c\u0435\u0442\u043e\u0434 <code>returnValue<\/code> \u0442\u0430\u043a \u043a\u0430\u043a \u0443 \u043d\u0430\u0441 \u0437\u0434\u0435\u0441\u044c \u0431\u0443\u0434\u0435\u0442 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c\u0441\u044f \u043d\u0435 \u043f\u0443\u0441\u0442\u043e\u0439 <code>observable<\/code> \u0430 \u043d\u0430\u0448 \u0442\u0435\u0441\u0442\u043e\u0432\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 <code>testComment<\/code>, \u0438 \u0442\u0430\u043a\u0436\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0438 \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043c\u0435\u0442\u043e\u0434 <code>of<\/code> \u0438\u0437 <code>rxjs<\/code>. \u0417\u0430\u0442\u0435\u043c \u043f\u043e\u043b\u043e\u0436\u0438\u043b\u0438 \u0432\u0441\u0435 \u044d\u0442\u043e \u0432 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e <code>spy.<br \/><\/code><br \/>\u0414\u0430\u043b\u0435\u0435 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043c\u0435\u0442\u043e\u0434 <code>add<\/code> \u043d\u0430\u0448\u0435\u0433\u043e<\/p>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-383055","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/383055","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=383055"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/383055\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=383055"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=383055"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=383055"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}