Skip to content

Commit 830db4a

Browse files
committed
Fix broken tests
1 parent a93eb74 commit 830db4a

1 file changed

Lines changed: 15 additions & 10 deletions

File tree

src/app/component/search/search.component.spec.ts

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
import { ComponentFixture, TestBed } from '@angular/core/testing';
22

3+
import { HarnessLoader } from '@angular/cdk/testing';
4+
import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed';
35
import { HttpHandler, provideHttpClient } from '@angular/common/http';
6+
import { MatSelectHarness } from '@angular/material/select/testing';
47
import { By } from '@angular/platform-browser';
58
import { PostService } from '../../service/rest/post/post.service';
69
import { SearchComponent } from './search.component';
710

811
describe('SearchComponent', () => {
912
let component: SearchComponent;
1013
let fixture: ComponentFixture<SearchComponent>;
14+
let loader: HarnessLoader;
1115

1216
beforeEach(async () => {
1317
await TestBed.configureTestingModule({
@@ -18,46 +22,47 @@ describe('SearchComponent', () => {
1822
fixture = TestBed.createComponent(SearchComponent);
1923
component = fixture.componentInstance;
2024
fixture.detectChanges();
25+
loader = TestbedHarnessEnvironment.loader(fixture);
2126
});
2227

2328
it('should create', () => {
2429
expect(component).toBeTruthy();
2530
});
2631

27-
it('should ensure default state on creation', () => {
28-
const searchBy: HTMLElement = fixture.debugElement.query(
29-
By.css('#search-by')
30-
).nativeElement;
32+
it('should ensure default state on creation', async () => {
3133
const searchText = fixture.debugElement.query(
3234
By.css('#search-text')
3335
).nativeElement;
3436
const searchButton = fixture.debugElement.query(
3537
By.css('#search')
3638
).nativeElement;
3739

38-
expect(searchBy.getAttribute('ng-reflect-value')).toBe('All');
40+
const selectHarness = await loader.getHarness(MatSelectHarness);
41+
const selectedValue = await selectHarness.getValueText();
42+
43+
expect(selectedValue).toBe('All');
3944
expect(searchText.disabled).toBeTrue();
4045
expect(searchButton.disabled).toBeFalse();
4146
});
4247

43-
it('should ensure correct state on selection change', () => {
48+
it('should ensure correct state on selection change', async () => {
4449
// Change selection value
4550
component.selected = 'Id';
4651
component.onSelectionChanged(component.selected);
4752

4853
fixture.detectChanges();
4954

50-
const searchBy: HTMLElement = fixture.debugElement.query(
51-
By.css('#search-by')
52-
).nativeElement;
5355
const searchText = fixture.debugElement.query(
5456
By.css('#search-text')
5557
).nativeElement;
5658
const searchButton = fixture.debugElement.query(
5759
By.css('#search')
5860
).nativeElement;
5961

60-
expect(searchBy.getAttribute('ng-reflect-value')).toBe('Id');
62+
const selectHarness = await loader.getHarness(MatSelectHarness);
63+
const selectedValue = await selectHarness.getValueText();
64+
65+
expect(selectedValue).toBe('Id');
6166
expect(searchText.disabled).toBeFalse();
6267
expect(searchButton.disabled).toBeTrue();
6368

0 commit comments

Comments
 (0)