DEV: prevents route action to crash in tests (#28409)

`routeAction` is testing at runtime that a route exists when in debug mode. However in the case of components tested in isolation there's no existing route which was causing an exception, this commit prevents this check in this case as it's irrelevant.
This commit is contained in:
Joffrey JAFFEUX 2024-08-17 13:52:20 +02:00 committed by GitHub
parent 2f8dc64caf
commit ea8516b38d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -5,6 +5,7 @@ import { assert, runInDebug } from "@ember/debug";
import { computed, get } from "@ember/object";
import { getOwner } from "@ember/owner";
import { join } from "@ember/runloop";
import { isTesting } from "discourse-common/config/environment";
function getCurrentRouteInfos(router) {
let routerLib = router._routerMicrolib || router.router;
@ -30,13 +31,15 @@ function getRouteWithAction(router, actionName) {
function routeAction(actionName, router, ...params) {
assert("[ember-route-action-helper] Unable to lookup router", router);
runInDebug(() => {
let { handler } = getRouteWithAction(router, actionName);
assert(
`[ember-route-action-helper] Unable to find action ${actionName}`,
handler
);
});
if (!isTesting() || router.currentRoute) {
runInDebug(() => {
let { handler } = getRouteWithAction(router, actionName);
assert(
`[ember-route-action-helper] Unable to find action ${actionName}`,
handler
);
});
}
return function (...invocationArgs) {
let { action, handler } = getRouteWithAction(router, actionName);