2017-01-09 12 views
7

'myPipe' adlı özel bir pipom var. Ben 'myPipe' boru benim birim test ts hata bulunamadı bulunamadı. Benim .spec.tsAçısal 2 Birim Testi: Özel Boru hatası Boru bulunamadı

içe ve beyan ne

Pleas tavsiye burada .spec.ts

import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 
import { By } from '@angular/platform-browser'; 
import { DebugElement } from '@angular/core'; 

import { MyComponent } from './main-page-carousel.component'; 

describe('CarouselComponent',() => { 
    let component: MyComponent ; 
    let fixture: ComponentFixture<MyComponent>; 

    beforeEach(async(() => { 
    TestBed.configureTestingModule({ 
     declarations: [ MyComponent ], 
    }) 
    .compileComponents(); 
    })); 

    beforeEach(() => { 
    fixture = TestBed.createComponent(MyComponent); 
    component = fixture.componentInstance; 
    fixture.detectChanges(); 
    }); 

    it('should create',() => { 
    expect(component).toBeTruthy(); 
    }); 
}); 

teşekkürler olduğunu!

+0

'myPipe' hakkında konuşuyorsunuz, ancak testiniz bir' CarouselComponent' ile ilgili? yerine benim "MyPipe" almamalısınız? –

+0

Ayrıca bu "boru bulunamadı" girişini de kontrol edin: http://stackoverflow.com/questions/39007130/the-pipe-could-not-be-found-angular2-custom-pipe/40770507#40770507 – Karl

cevap

0

Eğer

import { TestBed, async } from '@angular/core/testing'; 
import { MyPipe } from 'here put your custom pipe path'; 

describe('Pipe: MyPipe',() => { 
    it('create an instance',() => { 
    let pipe = new MyPipe(); 
    expect(pipe).toBeTruthy(); 
    }); 
}); 
0

gibi bir şey başlamalıdır ben aynı sorunu vardı ve benim spec.ts için aşağıdaki "sahte boru" ekleyerek sabit: Eğer zorunda Sonra

import {Pipe, PipeTransform} from '@angular/core'; 

@Pipe({name: 'myPipe'}) 
class MockPipe implements PipeTransform { 
    transform(value: number): number { 
     // blah blah 
     return value; 
    } 
} 

TestBed configureTestingModule beyanlarına MockPipe ekleyin:

TestBed.configureTestingModule({ 
    declarations: [ MyComponentUnderTesting, MockPipe ] 
}) 
10

Bunu yapmak mümkün olmalıdır:

import { MyPipe } from 'here put your custom pipe path'; 
    TestBed.configureTestingModule({ 
    declarations: [ MyComponentUnderTesting, MyPipe ] 
    })