Skip to content

Commit 36648c4

Browse files
fix: invoke initialNavigation in zone (#315)
1 parent 09dad6a commit 36648c4

File tree

1 file changed

+19
-15
lines changed

1 file changed

+19
-15
lines changed

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

+19-15
Original file line numberDiff line numberDiff line change
@@ -122,31 +122,35 @@ export async function render<SutType, WrapperType = SutType>(
122122

123123
const router = inject(Router);
124124
if (typeof router?.initialNavigation === 'function') {
125-
router?.initialNavigation();
125+
if (zone) {
126+
zone.run(() => router?.initialNavigation());
127+
} else {
128+
router?.initialNavigation();
129+
}
126130
}
127131

128132
const navigate = async (elementOrPath: Element | string, basePath = ''): Promise<boolean> => {
129133
const href = typeof elementOrPath === 'string' ? elementOrPath : elementOrPath.getAttribute('href');
130134
const [path, params] = (basePath + href).split('?');
131135
const queryParams = params
132136
? params.split('&').reduce((qp, q) => {
133-
const [key, value] = q.split('=');
134-
const currentValue = qp[key];
135-
if (typeof currentValue === 'undefined') {
136-
qp[key] = value;
137-
} else if (Array.isArray(currentValue)) {
138-
qp[key] = [...currentValue, value];
139-
} else {
140-
qp[key] = [currentValue, value];
141-
}
142-
return qp;
143-
}, {} as Record<string, string | string[]>)
137+
const [key, value] = q.split('=');
138+
const currentValue = qp[key];
139+
if (typeof currentValue === 'undefined') {
140+
qp[key] = value;
141+
} else if (Array.isArray(currentValue)) {
142+
qp[key] = [...currentValue, value];
143+
} else {
144+
qp[key] = [currentValue, value];
145+
}
146+
return qp;
147+
}, {} as Record<string, string | string[]>)
144148
: undefined;
145149

146150
const navigateOptions: NavigationExtras | undefined = queryParams
147151
? {
148-
queryParams,
149-
}
152+
queryParams,
153+
}
150154
: undefined;
151155

152156
const doNavigate = () => {
@@ -411,7 +415,7 @@ if (typeof process === 'undefined' || !process.env?.ATL_SKIP_AUTO_CLEANUP) {
411415
}
412416

413417
@Component({ selector: 'atl-wrapper-component', template: '' })
414-
class WrapperComponent { }
418+
class WrapperComponent {}
415419

416420
/**
417421
* Wrap findBy queries to poke the Angular change detection cycle

0 commit comments

Comments
 (0)