Skip to content

Commit e2bebe9

Browse files
hanslalexeagle
authored andcommitted
test: add a test for deferred jobs
Just one more bit of coverage.
1 parent c4798b6 commit e2bebe9

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

packages/angular_devkit/core/src/experimental/jobs/simple-scheduler_spec.ts

+31
Original file line numberDiff line numberDiff line change
@@ -590,5 +590,36 @@ describe('SimpleScheduler', () => {
590590
expect(await job.output.toPromise()).toBe(103);
591591
expect(outputs).toEqual([101, 103]);
592592
});
593+
594+
it('works deferred', async () => {
595+
// This is a more complex test. The job returns an output deferred from the input
596+
registry.register(
597+
'job',
598+
createJobHandler<number, number, number>((argument, context) => {
599+
return new Observable<number>(subscriber => {
600+
context.input.subscribe(x => {
601+
if (x === null) {
602+
setTimeout(() => subscriber.complete(), 10);
603+
} else {
604+
setTimeout(() => subscriber.next(parseInt('' + x) + argument), x);
605+
}
606+
});
607+
});
608+
}),
609+
);
610+
611+
const job = scheduler.schedule('job', 100);
612+
const outputs: number[] = [];
613+
614+
job.output.subscribe(x => outputs.push(x as number));
615+
616+
job.input.next(1);
617+
job.input.next(2);
618+
job.input.next(3);
619+
job.input.next(null);
620+
621+
expect(await job.output.toPromise()).toBe(103);
622+
expect(outputs).toEqual(jasmine.arrayWithExactContents([101, 102, 103]));
623+
});
593624
});
594625
});

0 commit comments

Comments
 (0)