Reputation: 703
I am trying to setup jasmine tests as explained here in official angular 2 documentation - https://angular.io/docs/ts/latest/guide/testing.html but the example for Pipe Testing just does not work. When I run the tests, I see only the specs for Hero working and the results coming to the browser.
If I comment out the Pipe annotation, only then the tests work :
````
import { Pipe, PipeTransform } from '@angular/core';
//@Pipe({ name: 'my-uppercase' })
export class MyUppercasePipe implements PipeTransform {
transform(value: string) {
return value;
}
}
````
Can anyone help me what needs to be added to get the tests work with pipe annotations? The modified code after following the tutorial is available here - https://github.com/rohans84/quickstart
Upvotes: 3
Views: 312
Reputation: 1164
The following setup works for me.
Pipe
import { Pipe, PipeTransform } from '@angular/core';
@Pipe({
name: 'sample'
})
export class SamplePipe implements PipeTransform {
transform(value: any, args?: any): any {
return null;
}
}
Spec
import { SamplePipe } from './sample.pipe';
describe('Pipe: Sample', () => {
it('create an instance', () => {
let pipe = new SamplePipe();
expect(pipe).toBeTruthy();
});
});
Testing Guide
The testing guide is not up to date. It's mentioned on the top of https://angular.io/docs/ts/latest/guide/testing.html
[EDIT]
I use Karma to run my tests. I have a setup for running Tests on GitHub: http://github.com/GregOnNet/angular2-testing-playground
I use angular-cli to manage my Angular 2 projects.
Hope this helps
Upvotes: 1