Skip to content

fix: invoke initialNavigation in zone #315

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 22, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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