docs: add docs for fakeAsync test with custom macroTask in aio (#21669)
PR Close #21669
This commit is contained in:

committed by
Kara Erickson

parent
f39551ce7e
commit
24f1dd3b81
@ -0,0 +1,27 @@
|
||||
import { TestBed, async, tick, fakeAsync } from '@angular/core/testing';
|
||||
import { CanvasComponent } from './canvas.component';
|
||||
describe('CanvasComponent', () => {
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [
|
||||
CanvasComponent
|
||||
],
|
||||
}).compileComponents();
|
||||
}));
|
||||
beforeEach(() => {
|
||||
window['__zone_symbol__FakeAsyncTestMacroTask'] = [
|
||||
{
|
||||
source: 'HTMLCanvasElement.toBlob',
|
||||
callbackArgs: [{ size: 200 }]
|
||||
}
|
||||
];
|
||||
});
|
||||
it('should be able to generate blob data from canvas', fakeAsync(() => {
|
||||
const fixture = TestBed.createComponent(CanvasComponent);
|
||||
fixture.detectChanges();
|
||||
tick();
|
||||
const app = fixture.debugElement.componentInstance;
|
||||
expect(app.blobSize).toBeGreaterThan(0);
|
||||
}));
|
||||
});
|
||||
|
@ -0,0 +1,25 @@
|
||||
import { Component, AfterViewInit, ViewChild } from '@angular/core';
|
||||
|
||||
@Component({
|
||||
selector: 'sample-canvas',
|
||||
template: '<canvas #sampleCanvas width="200" height="200"></canvas>'
|
||||
})
|
||||
export class CanvasComponent implements AfterViewInit {
|
||||
blobSize: number;
|
||||
@ViewChild('sampleCanvas') sampleCanvas;
|
||||
|
||||
constructor() { }
|
||||
|
||||
ngAfterViewInit() {
|
||||
const canvas = this.sampleCanvas.nativeElement;
|
||||
const context = canvas.getContext('2d');
|
||||
if (context) {
|
||||
context.clearRect(0, 0, 200, 200);
|
||||
context.fillStyle = '#FF1122';
|
||||
context.fillRect(0, 0, 200, 200);
|
||||
canvas.toBlob((blob: any) => {
|
||||
this.blobSize = blob.size;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user