@@ -725,6 +725,61 @@ test('plugin metadata - decorators', t => {
725
725
}
726
726
} )
727
727
728
+ test ( 'plugin metadata - decorators - should throw' , t => {
729
+ t . plan ( 1 )
730
+ const fastify = Fastify ( )
731
+
732
+ fastify . decorate ( 'plugin1' , true )
733
+ fastify . decorateReply ( 'plugin1' , true )
734
+
735
+ plugin [ Symbol . for ( 'skip-override' ) ] = true
736
+ plugin [ Symbol . for ( 'plugin-meta' ) ] = {
737
+ decorators : {
738
+ fastify : [ 'plugin1' ] ,
739
+ reply : [ 'plugin1' ] ,
740
+ request : [ 'plugin1' ]
741
+ }
742
+ }
743
+
744
+ fastify . register ( plugin )
745
+ fastify . ready ( ( err ) => {
746
+ t . equals ( err . message , "The decorator 'plugin1' is not present in Request" )
747
+ } )
748
+
749
+ function plugin ( instance , opts , next ) {
750
+ instance . decorate ( 'plugin' , true )
751
+ next ( )
752
+ }
753
+ } )
754
+
755
+ test ( 'plugin metadata - decorators - should throw with plugin name' , t => {
756
+ t . plan ( 1 )
757
+ const fastify = Fastify ( )
758
+
759
+ fastify . decorate ( 'plugin1' , true )
760
+ fastify . decorateReply ( 'plugin1' , true )
761
+
762
+ plugin [ Symbol . for ( 'skip-override' ) ] = true
763
+ plugin [ Symbol . for ( 'plugin-meta' ) ] = {
764
+ name : 'the-plugin' ,
765
+ decorators : {
766
+ fastify : [ 'plugin1' ] ,
767
+ reply : [ 'plugin1' ] ,
768
+ request : [ 'plugin1' ]
769
+ }
770
+ }
771
+
772
+ fastify . register ( plugin )
773
+ fastify . ready ( ( err ) => {
774
+ t . equals ( err . message , "The decorator 'plugin1' required by 'the-plugin' is not present in Request" )
775
+ } )
776
+
777
+ function plugin ( instance , opts , next ) {
778
+ instance . decorate ( 'plugin' , true )
779
+ next ( )
780
+ }
781
+ } )
782
+
728
783
test ( 'plugin metadata - dependencies' , t => {
729
784
t . plan ( 1 )
730
785
const fastify = Fastify ( )
0 commit comments