Skip to content

Commit

Permalink
fix: invoke initialNavigation in zone (#315)
Browse files Browse the repository at this point in the history
  • Loading branch information
timdeschryver authored Aug 22, 2022
1 parent 09dad6a commit 36648c4
Showing 1 changed file with 19 additions and 15 deletions.
34 changes: 19 additions & 15 deletions projects/testing-library/src/lib/testing-library.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,31 +122,35 @@ export async function render<SutType, WrapperType = SutType>(

const router = inject(Router);
if (typeof router?.initialNavigation === 'function') {
router?.initialNavigation();
if (zone) {
zone.run(() => router?.initialNavigation());
} else {
router?.initialNavigation();
}
}

const navigate = async (elementOrPath: Element | string, basePath = ''): Promise<boolean> => {
const href = typeof elementOrPath === 'string' ? elementOrPath : elementOrPath.getAttribute('href');
const [path, params] = (basePath + href).split('?');
const queryParams = params
? params.split('&').reduce((qp, q) => {
const [key, value] = q.split('=');
const currentValue = qp[key];
if (typeof currentValue === 'undefined') {
qp[key] = value;
} else if (Array.isArray(currentValue)) {
qp[key] = [...currentValue, value];
} else {
qp[key] = [currentValue, value];
}
return qp;
}, {} as Record<string, string | string[]>)
const [key, value] = q.split('=');
const currentValue = qp[key];
if (typeof currentValue === 'undefined') {
qp[key] = value;
} else if (Array.isArray(currentValue)) {
qp[key] = [...currentValue, value];
} else {
qp[key] = [currentValue, value];
}
return qp;
}, {} as Record<string, string | string[]>)
: undefined;

const navigateOptions: NavigationExtras | undefined = queryParams
? {
queryParams,
}
queryParams,
}
: undefined;

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

@Component({ selector: 'atl-wrapper-component', template: '' })
class WrapperComponent { }
class WrapperComponent {}

/**
* Wrap findBy queries to poke the Angular change detection cycle
Expand Down

0 comments on commit 36648c4

Please sign in to comment.