2017-01-09 19 views
7

मेरे पास 'myPipe' नामक एक कस्टम पाइप है। मुझे पाइप 'मायपाइप' मिल रहा है मेरे यूनिट टेस्ट टीएस में त्रुटि नहीं मिली।कोणीय 2 यूनिट टेस्ट: कस्टम पाइप त्रुटि पाइप नहीं मिली

दलीलों सलाह क्या आयात और मेरे .spec.ts

में घोषित करने के लिए यहाँ मेरी .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(); 
    }); 
}); 

धन्यवाद है!

+0

आप 'मायपाइप' के बारे में बात कर रहे हैं लेकिन आपका परीक्षण 'कैरोसेल कॉम्पोनेंट' से संबंधित है? आपको इसके बजाय 'myPipe' आयात नहीं करना चाहिए? –

+0

यह भी देखें "पाइप नहीं मिला" प्रविष्टि: http://stackoverflow.com/questions/39007130/the-pipe-could-not-be-found-angular2- कस्टम-pipe/40770507#40770507 – Karl

उत्तर

0

आप की तरह

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

कुछ शुरू कर देना चाहिए मैं एक ही समस्या थी, और निम्न "नकली पाइप" मेरे spec.ts को जोड़कर तय: फिर

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

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

आप करने के लिए है टेस्टबेड configureTestingModule घोषणाओं को MockPipe जोड़ें:

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

ऐसा करने के लिए सक्षम होना चाहिए:

import { MyPipe } from 'here put your custom pipe path'; 
    TestBed.configureTestingModule({ 
    declarations: [ MyComponentUnderTesting, MyPipe ] 
    }) 
संबंधित मुद्दे