Since it .pipe()
is still in the Observable prototype, you can use your surveillance technique.
lettable (oops, ), - .
, app.component.spec.ts CLI. , , , TestScheduler, .
import { TestBed, async } from '@angular/core/testing';
import { AppComponent } from './app.component';
import { Observable } from 'rxjs/Observable';
import { debounceTime, take, tap } from 'rxjs/operators';
import { TestScheduler } from 'rxjs/Rx';
export function mockPipe(...mockArgs) {
const originalPipe = Observable.prototype.pipe;
spyOn(Observable.prototype, 'pipe').and.callFake(function(...actualArgs) {
const args = [...actualArgs];
mockArgs.forEach((mockArg, index) => {
if(mockArg) {
args[index] = mockArg;
}
});
return originalPipe.call(this, ...args);
});
}
describe('AppComponent', () => {
it('should test lettable operators', () => {
const scheduler = new TestScheduler(null);
mockPipe(null, debounceTime(300, scheduler));
const sut = Observable.timer(0, 300).take(10)
.pipe(
tap(x => console.log('before ', x)),
debounceTime(300),
tap(x => console.log('after ', x)),
take(4),
);
sut.subscribe((data) => console.log(data));
scheduler.flush();
});
});