File tree 2 files changed +36
-1
lines changed
ember-glimmer/lib/components
2 files changed +36
-1
lines changed Original file line number Diff line number Diff line change @@ -313,7 +313,8 @@ import {
313
313
deprecate ,
314
314
get ,
315
315
computed ,
316
- flaggedInstrument
316
+ flaggedInstrument ,
317
+ runInDebug
317
318
} from 'ember-metal' ;
318
319
import {
319
320
deprecatingAlias ,
@@ -711,6 +712,26 @@ const LinkComponent = EmberComponent.extend({
711
712
712
713
let routing = get ( this , '_routing' ) ;
713
714
let queryParams = get ( this , 'queryParams.values' ) ;
715
+
716
+ runInDebug ( ( ) => {
717
+ /*
718
+ * Unfortunately, to get decent error messages, we need to do this.
719
+ * In some future state we should be able to use a "feature flag"
720
+ * which allows us to strip this without needing to call it twice.
721
+ *
722
+ * if (isDebugBuild()) {
723
+ * // Do the useful debug thing, probably including try/catch.
724
+ * } else {
725
+ * // Do the performant thing.
726
+ * }
727
+ */
728
+ try {
729
+ routing . generateURL ( qualifiedRouteName , models , queryParams ) ;
730
+ } catch ( e ) {
731
+ assert ( 'You attempted to define a `{{link-to "' + qualifiedRouteName + '"}}` but did not pass the parameters required for generating its dynamic segments. ' + e . message ) ;
732
+ }
733
+ } ) ;
734
+
714
735
return routing . generateURL ( qualifiedRouteName , models , queryParams ) ;
715
736
} ) ,
716
737
Original file line number Diff line number Diff line change @@ -1249,6 +1249,20 @@ QUnit.test('the {{link-to}} helper does not call preventDefault if `preventDefau
1249
1249
equal ( event . isDefaultPrevented ( ) , false , 'should not preventDefault' ) ;
1250
1250
} ) ;
1251
1251
1252
+ QUnit . test ( 'the {{link-to}} helper throws a useful error if you invoke it wrong' , function ( ) {
1253
+ expect ( 1 ) ;
1254
+
1255
+ setTemplate ( 'application' , compile ( "{{#link-to 'post'}}Post{{/link-to}}" ) ) ;
1256
+
1257
+ Router . map ( function ( ) {
1258
+ this . route ( 'post' , { path : 'post/:post_id' } ) ;
1259
+ } ) ;
1260
+
1261
+ QUnit . throws ( function ( ) {
1262
+ bootApplication ( ) ;
1263
+ } , / ( Y o u a t t e m p t e d t o d e f i n e a ` \{ \{ l i n k - t o " p o s t " \} \} ` b u t d i d n o t p a s s t h e p a r a m e t e r s r e q u i r e d f o r g e n e r a t i n g i t s d y n a m i c s e g m e n t s .| Y o u m u s t p r o v i d e p a r a m ` p o s t _ i d ` t o ` g e n e r a t e ` ) / ) ;
1264
+ } ) ;
1265
+
1252
1266
QUnit . test ( 'the {{link-to}} helper does not throw an error if its route has exited' , function ( ) {
1253
1267
expect ( 0 ) ;
1254
1268
You can’t perform that action at this time.
0 commit comments