Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions projects/testing-library/src/lib/testing-library.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, Type, NgZone, SimpleChange, OnChanges, SimpleChanges } from '@angular/core';
import { ChangeDetectorRef, Component, Type, NgZone, SimpleChange, OnChanges, SimpleChanges } from '@angular/core';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { BrowserAnimationsModule, NoopAnimationsModule } from '@angular/platform-browser/animations';
Expand Down Expand Up @@ -117,7 +117,7 @@ export async function render<SutType, WrapperType = SutType>(
fixture.componentInstance.ngOnChanges(changes);
}

detectChanges();
fixture.componentRef.injector.get(ChangeDetectorRef).detectChanges();
};

const inject = TestBed.inject || TestBed.get;
Expand Down
23 changes: 22 additions & 1 deletion projects/testing-library/tests/rerender.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Component, Input, OnChanges, SimpleChanges } from '@angular/core';
import { ChangeDetectionStrategy, Component, Input, OnChanges, SimpleChanges } from '@angular/core';
import { screen } from '@testing-library/dom';
import { render } from '../src/public_api';

@Component({
Expand Down Expand Up @@ -50,3 +51,23 @@ test('will call ngOnChanges on rerender', async () => {
component.getByText(name);
expect(nameChanged).toBeCalledWith(name, false);
})

@Component({
changeDetection: ChangeDetectionStrategy.OnPush,
selector: 'fixture-onpush',
template: `
<div data-testid="number" [class.active]="activeField === 'number'">Number</div>
`,
})
class FixtureWithOnPushComponent {
@Input() activeField: string;
}

test('update properties on rerender', async () => {
const { rerender } = await render(FixtureWithOnPushComponent);
const numberHtmlElementRef = screen.queryByTestId('number');

expect(numberHtmlElementRef).not.toHaveClass('active');
rerender({ activeField: 'number' });
expect(numberHtmlElementRef).toHaveClass('active');
})