调用完query之后,如果不显式调用fixture.detectChanges, 则query返回的handle里,是无法获取到视图内容的。...the user is authenticated', () => { expect(el.nativeElement.textContent.trim()).toBe(''); fixture.detectChanges
TestBed.createComponent(MockComponent); component = fixture.componentInstance; fixture.detectChanges...'findFirstFocusable').and.returnValue(el); spyOn(el, 'focus').and.callThrough(); fixture.detectChanges...); expect(service.findFirstFocusable).toHaveBeenCalled(); component.jerry = 2; fixture.detectChanges...detectChanges会触发ngZone的run方法,进而调用_tick函数: ? 以callback的方式回调_tick(): ?
be available', () => { let button = getContinueBtn(); console.log('before call fixture.detectChanges...: ' + button); fixture.detectChanges(); button = getContinueBtn(); console.log('after...call fixture.detectChanges: ' + button); expect(button).toBeTruthy(); }); }); }); 测试结果:...由此可见,在fixture.detectChanges()之前,我们是无法使用fixture.debugElement.query获取UI元素实例的。 ?...当然,为了避免在每个it spec里访问button之前都事先调用fixture.detectChanges, 我们可以把这个调用放到describe continue button内部的beforeEach
如果没有调用fixture.detectChanges, element context的innerHTML里根本就看不到button的源代码: ? ? ?
_view = _view; } detectChanges() { detectChangesInRootView(this.
).and.returnValue(of(mockSupportedDeliveryModes)); component.ngOnInit(); fixture.detectChanges...disabled when delivery mode is not selected', () => { setDeliveryModeId(null); fixture.detectChanges...delivery mode is selected', () => { setDeliveryModeId(mockDeliveryMode1.code); fixture.detectChanges...> { spyOn(component, 'next'); setDeliveryModeId(mockDeliveryMode1.code); fixture.detectChanges...(); getContinueBtn().nativeElement.click(); fixture.detectChanges(); expect(component.next
button.disabled: ' + button.nativeElement.disabled ); setDeliveryModeId(null); fixture.detectChanges...it('should be available', () => { const button = getContinueBtn(); console.log('fixture.detectChanges...is put in beforeEach: ' + button); //fixture.detectChanges(); //button = getContinueBtn(...); //console.log('after call fixture.detectChanges: ' + button); expect(button).toBeTruthy...disabled when delivery mode is not selected', () => { setDeliveryModeId(null); fixture.detectChanges
const el: HTMLElement = fixture.debugElement.query(By.css('#a')) .nativeElement; fixture.detectChanges...nativeElement; spyOn(keyboardFocusService, 'findFirstFocusable').and.returnValue(el); fixture.detectChanges...spyOn( keyboardFocusService, 'findFirstFocusable' ).and.returnValue(el); fixture.detectChanges...spiedFirstFocusable).toHaveBeenCalledTimes(ELEMENT_FOCUSED_TIME); component.modelB = '1'; fixture.detectChanges...spiedFirstFocusable).toHaveBeenCalledTimes(ELEMENT_FOCUSED_TIME); component.modelA = '1'; fixture.detectChanges
在调用了fixture.detectChanges的情况下: ? css返回一个新的函数,输入参数是debugElement: ? ?...掉了detectChanges之后,innerHTML里有的markup: ? 但奇怪的是disabled为"". 取得context: ? context结果: ? parent tnode: ?
实现扫描对比的方法是调用DbContext.ChangeTracker的DetectChanges方法。 ...Entity Framework Code First的DbContext.DetectChanges在检测实例对象的变动时,大部分情况不会有性能的问题。...但当有大量的实例对象在内存中,或DbContext有大量的操作时,自动的DetectChanges行为可能会一定程度的影响性能。
局限性:如果Component的changeDetection的值为ChangeDetectionStrategy.OnPush而不是Default,那么fixture.detectChanges()只有在一个...fixture.componentInstance; tableRendererService = TestBed.inject(TableRendererService); fixture.detectChanges
component.mode.controls['deliveryModeId'].setValue(null); fixture.detectChanges(); 果然,这次就能检索到按钮了...注释掉fixture.detectChanges()后,button为null: ? 要获取更多Jerry的原创文章,请关注公众号"汪子熙": ?
detectChanges:在测试中的Angular变化检测。 每个测试程序都通过调用fixture.detectChanges() 来通知Angular执行变化检测。...使用例子: it('should show quote after getQuote promise (async)', async(() => { fixture.detectChanges();...fixture.whenStable().then(() => { // wait for async getQuote fixture.detectChanges();...然后测试程序继续运行,并开始另一轮的变化检测(fixture.detectChanges ),通知Angular使用名言来更新DOM。...使用例子 it('should show quote after getQuote promise (done)', done => { fixture.detectChanges(); //
TWICE in the same test spec, [disabled] and deliveryModeInvalid will LOSE synchronization, even fixture.detectChanges...setValue(value); function setDeliveryModeIdNull(){ setDeliveryModeId(null); fixture.detectChanges...trace(null); } function setDeliveryModeIdValid(){ setDeliveryModeId('a'); fixture.detectChanges
query(By.css('button.increment')) .triggerEventHandler('click', null); tick(2000); fixture.detectChanges...; expect(value).toEqual('0'); // value should still be 0 after 2 seconds tick(3000); fixture.detectChanges....query(By.css('button.increment')) .triggerEventHandler('click', null); flush(); fixture.detectChanges
: beforeEach(() => { fixture = TestBed.createComponent(ProductCarouselComponent); fixture.detectChanges
parentZoneDelegate.invoke: 调用callback,Angular单元测试代码里调用fixture.detectChanges, 内部放入zone执行的this.
angular/core'; 然后在构造函数里注入: constructor(private cd: ChangeDetectorRef) 最终在更新变量后,手动调用代码,强制页面检查刷新即可: this.cd.detectChanges...它其实有如下几个方法: class ChangeDetectorRef { markForCheck(): void detach(): void detectChanges(): void
')) .triggerEventHandler('click', null); fixture.whenStable().then(() => { fixture.detectChanges
一旦我执行上图116行的fixture.detectChanges(): ? 最后就会转而调用我自己Component里的ngOnInit钩子: ? Zone.prototype.run: ?
领取专属 10元无门槛券
手把手带您无忧上云