@@ -602,6 +602,63 @@ describe('The Croct plug', () => {
602
602
expect ( ( ) => croct . evaluate ( 'foo' , { timeout : 5 } ) ) . toThrow ( 'Croct is not plugged in.' ) ;
603
603
} ) ;
604
604
605
+ test ( 'should allow to test expressions' , async ( ) => {
606
+ const config : SdkFacadeConfiguration = { appId : APP_ID } ;
607
+ const sdkFacade = SdkFacade . init ( config ) ;
608
+
609
+ const initialize = jest . spyOn ( SdkFacade , 'init' ) . mockReturnValue ( sdkFacade ) ;
610
+
611
+ croct . plug ( config ) ;
612
+
613
+ expect ( initialize ) . toBeCalledWith ( config ) ;
614
+
615
+ const evaluate = jest . spyOn ( sdkFacade , 'evaluate' ) . mockResolvedValue ( true ) ;
616
+
617
+ const promise = croct . test ( 'user\'s name is "Carol"' , { timeout : 5 } ) ;
618
+
619
+ await expect ( promise ) . resolves . toBe ( true ) ;
620
+
621
+ expect ( evaluate ) . toBeCalledWith ( 'user\'s name is "Carol"' , { timeout : 5 } ) ;
622
+ } ) ;
623
+
624
+ test ( 'should test expressions assuming non-boolean results as false' , async ( ) => {
625
+ const config : SdkFacadeConfiguration = { appId : APP_ID } ;
626
+ const sdkFacade = SdkFacade . init ( config ) ;
627
+
628
+ const initialize = jest . spyOn ( SdkFacade , 'init' ) . mockReturnValue ( sdkFacade ) ;
629
+
630
+ croct . plug ( config ) ;
631
+
632
+ expect ( initialize ) . toBeCalledWith ( config ) ;
633
+
634
+ const evaluate = jest . spyOn ( sdkFacade , 'evaluate' ) . mockResolvedValue ( 'foo' ) ;
635
+
636
+ const promise = croct . test ( 'user\'s name is "Carol"' , { timeout : 5 } ) ;
637
+
638
+ await expect ( promise ) . resolves . toBe ( false ) ;
639
+
640
+ expect ( evaluate ) . toBeCalledWith ( 'user\'s name is "Carol"' , { timeout : 5 } ) ;
641
+ } ) ;
642
+
643
+ test ( 'should not test expressions assuming errors as false' , async ( ) => {
644
+ const config : SdkFacadeConfiguration = { appId : APP_ID } ;
645
+ const sdkFacade = SdkFacade . init ( config ) ;
646
+
647
+ const initialize = jest . spyOn ( SdkFacade , 'init' ) . mockReturnValue ( sdkFacade ) ;
648
+
649
+ croct . plug ( config ) ;
650
+
651
+ expect ( initialize ) . toBeCalledWith ( config ) ;
652
+
653
+ const evaluate = jest . spyOn ( sdkFacade , 'evaluate' ) . mockRejectedValue ( undefined ) ;
654
+
655
+ const promise = croct . test ( 'user\'s name is "Carol"' , { timeout : 5 } ) ;
656
+
657
+ await expect ( promise ) . rejects . toBeUndefined ( ) ;
658
+
659
+ expect ( evaluate ) . toBeCalledWith ( 'user\'s name is "Carol"' , { timeout : 5 } ) ;
660
+ } ) ;
661
+
605
662
test ( 'should wait for the plugins to disable before closing the SDK' , async ( ) => {
606
663
let unloadFooPlugin : ( ) => void = jest . fn ( ) ;
607
664
const fooDisable = jest . fn ( ) . mockImplementation ( ( ) => new Promise < void > ( resolve => {
0 commit comments