@@ -235,7 +235,7 @@ describe("Trial", () => {
235235 } ) ;
236236
237237 it ( "respects the `save_trial_parameters` parameter" , async ( ) => {
238- const consoleSpy = jest . spyOn ( console , "warn" ) . mockImplementation ( ) ;
238+ const consoleSpy = jest . spyOn ( console , "warn" ) . mockImplementation ( ( ) => { } ) ;
239239
240240 TestPlugin . setParameterInfos ( {
241241 stringParameter1 : { type : ParameterType . STRING } ,
@@ -560,6 +560,110 @@ describe("Trial", () => {
560560 } ) ;
561561 } ) ;
562562
563+ describe ( "with parameter type mismatches" , ( ) => {
564+ //TODO: redo these to expect errors on v9!
565+ let consoleSpy : jest . SpyInstance ;
566+
567+ beforeEach ( ( ) => {
568+ consoleSpy = jest . spyOn ( console , "warn" ) . mockImplementation ( ( ) => { } ) ;
569+ } ) ;
570+
571+ afterEach ( ( ) => {
572+ consoleSpy . mockRestore ( ) ;
573+ } ) ;
574+
575+ it ( "errors on non-boolean values for boolean parameters" , async ( ) => {
576+ TestPlugin . setParameterInfos ( {
577+ boolParameter : { type : ParameterType . BOOL } ,
578+ } ) ;
579+
580+ // this should work:
581+ await createTrial ( { type : TestPlugin , boolParameter : true } ) . run ( ) ;
582+
583+ // this shouldn't:
584+ await createTrial ( { type : TestPlugin , boolParameter : "foo" } ) . run ( ) ;
585+ expect ( consoleSpy ) . toHaveBeenCalledWith (
586+ 'A non-boolean value (`foo`) was provided for the boolean parameter "boolParameter" in the "test" plugin.'
587+ ) ;
588+ } ) ;
589+
590+ it ( "errors on non-string values for string parameters" , async ( ) => {
591+ TestPlugin . setParameterInfos ( {
592+ stringParameter : { type : ParameterType . STRING } ,
593+ } ) ;
594+
595+ // this should work:
596+ await createTrial ( { type : TestPlugin , stringParameter : "foo" } ) . run ( ) ;
597+
598+ // this shouldn't:
599+ await createTrial ( { type : TestPlugin , stringParameter : 1 } ) . run ( ) ;
600+ expect ( consoleSpy ) . toHaveBeenCalledWith (
601+ 'A non-string value (`1`) was provided for the parameter "stringParameter" in the "test" plugin.'
602+ ) ;
603+ } ) ;
604+
605+ it ( "errors on non-numeric values for numeric parameters" , async ( ) => {
606+ TestPlugin . setParameterInfos ( {
607+ intParameter : { type : ParameterType . INT } ,
608+ floatParameter : { type : ParameterType . FLOAT } ,
609+ } ) ;
610+
611+ // this should work:
612+ await createTrial ( { type : TestPlugin , intParameter : 1 , floatParameter : 1.5 } ) . run ( ) ;
613+
614+ // this shouldn't:
615+ await createTrial ( { type : TestPlugin , intParameter : "foo" , floatParameter : 1.5 } ) . run ( ) ;
616+ expect ( consoleSpy ) . toHaveBeenCalledWith (
617+ 'A non-numeric value (`foo`) was provided for the numeric parameter "intParameter" in the "test" plugin.'
618+ ) ;
619+
620+ await createTrial ( { type : TestPlugin , intParameter : 1 , floatParameter : "foo" } ) . run ( ) ;
621+ expect ( consoleSpy ) . toHaveBeenCalledWith (
622+ 'A non-numeric value (`foo`) was provided for the numeric parameter "floatParameter" in the "test" plugin.'
623+ ) ;
624+
625+ // this should warn but not error (behavior in v9):
626+ await createTrial ( { type : TestPlugin , intParameter : 1.5 , floatParameter : 1.5 } ) . run ( ) ;
627+ expect ( consoleSpy ) . toHaveBeenCalledWith (
628+ `A float value (\`1.5\`) was provided for the integer parameter "intParameter" in the "test" plugin. The value will be truncated to an integer.`
629+ ) ;
630+ } ) ;
631+
632+ it ( "errors on non-function values for function parameters" , async ( ) => {
633+ TestPlugin . setParameterInfos ( {
634+ functionParameter : { type : ParameterType . FUNCTION } ,
635+ } ) ;
636+
637+ // this should work:
638+ await createTrial ( { type : TestPlugin , functionParameter : ( ) => { } } ) . run ( ) ;
639+
640+ // this shouldn't:
641+ await createTrial ( { type : TestPlugin , functionParameter : "foo" } ) . run ( ) ;
642+ expect ( consoleSpy ) . toHaveBeenCalledWith (
643+ 'A non-function value (`foo`) was provided for the function parameter "functionParameter" in the "test" plugin.'
644+ ) ;
645+ } ) ;
646+
647+ it ( "errors on select parameters with values not in the options array" , async ( ) => {
648+ TestPlugin . setParameterInfos ( {
649+ selectParameter : {
650+ type : ParameterType . SELECT ,
651+ options : [ "foo" , "bar" ] ,
652+ } ,
653+ } ) ;
654+
655+ // this should work:
656+ await createTrial ( { type : TestPlugin , selectParameter : "foo" } ) . run ( ) ;
657+
658+ // this shouldn't:
659+
660+ await createTrial ( { type : TestPlugin , selectParameter : "baz" } ) . run ( ) ;
661+ expect ( consoleSpy ) . toHaveBeenCalledWith (
662+ 'The value "baz" is not a valid option for the parameter "selectParameter" in the "test" plugin. Valid options are: foo, bar.'
663+ ) ;
664+ } ) ;
665+ } ) ;
666+
563667 it ( "respects `default_iti` and `post_trial_gap``" , async ( ) => {
564668 dependencies . getDefaultIti . mockReturnValue ( 100 ) ;
565669 TestPlugin . setManualFinishTrialMode ( ) ;
0 commit comments