typescript Ejemplo de test para服务

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了typescript Ejemplo de test para服务相关的知识,希望对你有一定的参考价值。

import { TestBed, inject } from '@angular/core/testing';

import { CardService } from './card.service';
import {of} from 'rxjs';
import {CardModel} from '../models/card.model';

describe('Cardservice', () => {
  let cardService: CardService;
  let mockDataService;
  let card: CardModel;
  const CARDS: CardModel[] = [
    {
      id: 1,
      front: 'front',
      back: 'back',
      themeId: 1
    }
  ];

  beforeEach(() => {
    TestBed.configureTestingModule({
      providers: [CardService]
    });
  });

  beforeEach(() => {
    mockDataService = jasmine.createSpyObj([
      'getThemes',
      'getCards'
    ]);

    mockDataService.getCards.and.returnValue(of(CARDS));

    cardService = new CardService(mockDataService);
  });

  describe('CardService Creation', () => {
    it('should be created', () => {
      expect(cardService).toBeTruthy();
    });
  });

  describe('cardsArray', () => {
    it('should have one CardModel object', () => {
      expect(cardService.cardsArray.length).toBe(1);
    });
  });

  describe('getCard()', () => {
    it('should return one CardModel object', () => {
      card = cardService.getCard();
      expect(card).toEqual(CARDS[0]);
    });
  });

});

以上是关于typescript Ejemplo de test para服务的主要内容,如果未能解决你的问题,请参考以下文章

text ejemplo de vue

java Ejemplo de Java 8

PHP ejemplo de AJAX

PHP ejemplo de AJAX

xml Ejemplo del XML de curvas de nivel 100k

JavaScript Ejemplo de Ajax.Responders(原型)