Skip to content

Commit

Permalink
use constructor instead of property injection so mocked services can …
Browse files Browse the repository at this point in the history
…be passed
  • Loading branch information
thomasengels committed Feb 19, 2025
1 parent a75093a commit 4402a8d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ export class InboAutocompleteComponent<T extends Partial<{ [key: string]: any }>
items: Array<T>;
errorStateMatcher = new CustomErrorStateMatcher(() => this.showErrorMessage);

private changeDetectorRef = inject(ChangeDetectorRef);

constructor(public changeDetectorRef: ChangeDetectorRef){}

private _value: T;

get value(): T {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ describe('InboAutocompleteComponent', () => {
changeDetectorRef = mock(ChangeDetectorRefTestImpl);
mockSearchFunction = fnmock();

componentUnderTest = new InboAutocompleteComponent(
instance(changeDetectorRef),
);
componentUnderTest = new InboAutocompleteComponent(changeDetectorRef);
componentUnderTest.searchFunction = mockSearchFunction;
});

Expand Down Expand Up @@ -125,6 +123,9 @@ describe('InboAutocompleteComponent', () => {
beforeEach(() => {
itemsSubject = new Subject<Array<TestObject>>();
componentUnderTest.searchFunction = () => itemsSubject.asObservable();

changeDetectorRef = mock(ChangeDetectorRefTestImpl);
componentUnderTest = new InboAutocompleteComponent(changeDetectorRef);
});

it('should not do a search and set items to empty array if the given string has a length of less than the minimum number of characters', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import {InboDataTableComponent} from '../inbo-data-table.component';
import { InboDataTableColumnConfiguration } from '../column-configuration.model';
import {InboDataTableComponent, InboDatatableItem} from '../inbo-data-table.component';

describe('InboDataTableComponent', () => {

let componentUnderTest: InboDataTableComponent<TestDataClass>;
let componentUnderTest: InboDataTableComponent<any>;

beforeEach(() => {
componentUnderTest = new InboDataTableComponent();
Expand All @@ -17,13 +18,14 @@ describe('InboDataTableComponent', () => {
},
propA: {
name: 'Property A',
},
};
}
} as InboDataTableColumnConfiguration<InboDatatableItem>; // Explicitly cast

componentUnderTest.ngOnInit();

expect(componentUnderTest.displayedColumns).toEqual(['id', 'propA']);
});

});

});
Expand Down

0 comments on commit 4402a8d

Please sign in to comment.