小编Pet*_*eii的帖子

如何使用Angular 2中的日期管道测试元素的渲染?

我似乎无法测试在Angular 2中使用Date管道的组件(通过PhantomJS使用Karma).当我尝试时,我得到ORIGINAL EXCEPTION:ReferenceError:找不到变量:Intl

这是我的整个spec文件:

import { provide, PLATFORM_PIPES } from '@angular/core';
import { DatePipe } from '@angular/common';
import { addProviders, async, inject } from '@angular/core/testing';

import { Post, PostComponent, PostHtmlComponent } from './';
import { usingComponentFixture } from '../../test-helpers';

describe('Component: Post', () => {
  beforeEach(() => {
    provide(PLATFORM_PIPES, {useValue: DatePipe, multi: true });
    addProviders([PostComponent, PostHtmlComponent, ]);
  });

  it('should render an h1 tag with text matching the post title', 
    usingComponentFixture(PostComponent, fixture => {
        let component = <PostComponent>fixture.componentInstance;
        let element = …
Run Code Online (Sandbox Code Playgroud)

unit-testing karma-jasmine angular

8
推荐指数
4
解决办法
7180
查看次数

标签 统计

angular ×1

karma-jasmine ×1

unit-testing ×1