@@ -983,7 +983,54 @@ test('try-commit fails when calling commit twice', t => {
983
983
} ) . run ( ) . then ( result => {
984
984
t . false ( result . passed ) ;
985
985
t . ok ( result . error ) ;
986
- t . match ( result . error . message , / w a s a l r e a d y c a l l e d / ) ;
986
+ t . match ( result . error . message , / T h e c o m m i t \( \) w a s a l r e a d y c a l l e d / ) ;
987
+ t . is ( result . error . name , 'Error' ) ;
988
+ } ) ;
989
+ } ) ;
990
+
991
+ test ( 'try-commit fails when calling discard twice' , t => {
992
+ return ava ( a => {
993
+ return a . try ( b => b . pass ( ) ) . then ( res => {
994
+ res . discard ( ) ;
995
+ res . discard ( ) ;
996
+ } ) ;
997
+ } ) . run ( ) . then ( result => {
998
+ t . false ( result . passed ) ;
999
+ t . ok ( result . error ) ;
1000
+ t . match ( result . error . message , / T h e d i s c a r d \( \) w a s a l r e a d y c a l l e d / ) ;
1001
+ t . is ( result . error . name , 'Error' ) ;
1002
+ } ) ;
1003
+ } ) ;
1004
+
1005
+ test ( 'try-commit fails when calling discard on promise twice' , t => {
1006
+ return ava ( a => {
1007
+ const pr = a . try ( b => b . pass ( ) ) ;
1008
+ pr . discard ( ) ;
1009
+ pr . discard ( ) ;
1010
+
1011
+ return pr . then ( res => {
1012
+ t . is ( res , null ) ;
1013
+ } ) ;
1014
+ } ) . run ( ) . then ( result => {
1015
+ t . false ( result . passed ) ;
1016
+ t . ok ( result . error ) ;
1017
+ t . match ( result . error . message , / T h e d i s c a r d \( \) w a s a l r e a d y c a l l e d / ) ;
1018
+ t . is ( result . error . name , 'Error' ) ;
1019
+ } ) ;
1020
+ } ) ;
1021
+
1022
+ test ( 'try-commit fails when calling discard on promise after attempt resolved' , t => {
1023
+ return ava ( a => {
1024
+ const attemptPromise = a . try ( b => b . pass ( ) ) ;
1025
+ return attemptPromise . then ( res => {
1026
+ t . true ( res . passed ) ;
1027
+ res . commit ( ) ;
1028
+ attemptPromise . discard ( ) ;
1029
+ } ) ;
1030
+ } ) . run ( ) . then ( result => {
1031
+ t . false ( result . passed ) ;
1032
+ t . ok ( result . error ) ;
1033
+ t . match ( result . error . message , / A t t e m p t i s a l r e a d y r e s o l v e d / ) ;
987
1034
t . is ( result . error . name , 'Error' ) ;
988
1035
} ) ;
989
1036
} ) ;
0 commit comments