Skip to content

Commit ad0b2db

Browse files
committed
refactor: detectchanges inside wait callback
1 parent 76adbb2 commit ad0b2db

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

projects/testing-library/src/lib/testing-library.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,12 @@ export async function render<SutType, WrapperType = SutType>(
137137
attributes: boolean;
138138
characterData: boolean;
139139
};
140-
} = { container: fixture.nativeElement, interval: 50 },
140+
} = { container: fixture.nativeElement },
141141
): Promise<T> {
142-
const interval = setInterval(detectChanges, options.interval);
143-
return waitFor<T>(callback, options).finally(() => clearInterval(interval));
142+
return waitFor<T>(() => {
143+
detectChanges();
144+
return callback();
145+
}, options);
144146
}
145147

146148
function componentWaitForElementToBeRemoved<T>(
@@ -155,10 +157,12 @@ export async function render<SutType, WrapperType = SutType>(
155157
attributes: boolean;
156158
characterData: boolean;
157159
};
158-
} = { container: fixture.nativeElement, interval: 50 },
160+
} = { container: fixture.nativeElement },
159161
): Promise<T> {
160-
const interval = setInterval(detectChanges, options.interval);
161-
return waitForElementToBeRemoved<T>(callback, options).finally(() => clearInterval(interval));
162+
return waitForElementToBeRemoved<T>(() => {
163+
detectChanges();
164+
return callback();
165+
}, options);
162166
}
163167

164168
return {

0 commit comments

Comments
 (0)