@@ -15,17 +15,28 @@ const HelloMessage = require('./fixture/hello-message');
15
15
let lastFailure = null ;
16
16
let lastPassed = false ;
17
17
const assertions = assert . wrapAssertions ( {
18
- pass ( ) {
18
+ pass ( testObj ) {
19
+ if ( testObj !== assertions && ! ( testObj instanceof Test ) ) {
20
+ throw new Error ( 'Expected testObj' ) ;
21
+ }
19
22
lastPassed = true ;
20
23
} ,
21
24
22
- pending ( _ , promise ) {
25
+ pending ( testObj , promise ) {
26
+ if ( testObj !== assertions && ! ( testObj instanceof Test ) ) {
27
+ throw new Error ( 'Expected testObj' ) ;
28
+ }
29
+
23
30
promise . catch ( err => {
24
31
lastFailure = err ;
25
32
} ) ;
26
33
} ,
27
34
28
- fail ( _ , error ) {
35
+ fail ( testObj , error ) {
36
+ if ( testObj !== assertions && ! ( testObj instanceof Test ) ) {
37
+ throw new Error ( 'Expected testObj' ) ;
38
+ }
39
+
29
40
lastFailure = error ;
30
41
}
31
42
} ) ;
@@ -813,31 +824,27 @@ test('.snapshot()', t => {
813
824
updating
814
825
} ) ;
815
826
const setup = title => {
816
- const fauxTest = new Test ( {
827
+ return new Test ( {
817
828
title,
818
829
compareTestSnapshot : options => manager . compare ( options )
819
830
} ) ;
820
- const executionContext = {
821
- _test : fauxTest
822
- } ;
823
- return executionContext ;
824
831
} ;
825
832
826
833
passes ( t , ( ) => {
827
- const executionContext = setup ( 'passes' ) ;
828
- assertions . snapshot . call ( executionContext , { foo : 'bar' } ) ;
829
- assertions . snapshot . call ( executionContext , { foo : 'bar' } , { id : 'fixed id' } , 'message not included in snapshot report' ) ;
830
- assertions . snapshot . call ( executionContext , React . createElement ( HelloMessage , { name : 'Sindre' } ) ) ;
831
- assertions . snapshot . call ( executionContext , renderer . create ( React . createElement ( HelloMessage , { name : 'Sindre' } ) ) . toJSON ( ) ) ;
834
+ const testInstance = setup ( 'passes' ) ;
835
+ assertions . snapshot . call ( testInstance , { foo : 'bar' } ) ;
836
+ assertions . snapshot . call ( testInstance , { foo : 'bar' } , { id : 'fixed id' } , 'message not included in snapshot report' ) ;
837
+ assertions . snapshot . call ( testInstance , React . createElement ( HelloMessage , { name : 'Sindre' } ) ) ;
838
+ assertions . snapshot . call ( testInstance , renderer . create ( React . createElement ( HelloMessage , { name : 'Sindre' } ) ) . toJSON ( ) ) ;
832
839
} ) ;
833
840
834
841
{
835
- const executionContext = setup ( 'fails' ) ;
842
+ const testInstance = setup ( 'fails' ) ;
836
843
if ( updating ) {
837
- assertions . snapshot . call ( executionContext , { foo : 'bar' } ) ;
844
+ assertions . snapshot . call ( testInstance , { foo : 'bar' } ) ;
838
845
} else {
839
846
failsWith ( t , ( ) => {
840
- assertions . snapshot . call ( executionContext , { foo : 'not bar' } ) ;
847
+ assertions . snapshot . call ( testInstance , { foo : 'not bar' } ) ;
841
848
} , {
842
849
assertion : 'snapshot' ,
843
850
message : 'Did not match snapshot' ,
@@ -847,21 +854,21 @@ test('.snapshot()', t => {
847
854
}
848
855
849
856
failsWith ( t , ( ) => {
850
- const executionContext = setup ( 'fails (fixed id)' ) ;
851
- assertions . snapshot . call ( executionContext , { foo : 'not bar' } , { id : 'fixed id' } , 'different message, also not included in snapshot report' ) ;
857
+ const testInstance = setup ( 'fails (fixed id)' ) ;
858
+ assertions . snapshot . call ( testInstance , { foo : 'not bar' } , { id : 'fixed id' } , 'different message, also not included in snapshot report' ) ;
852
859
} , {
853
860
assertion : 'snapshot' ,
854
861
message : 'different message, also not included in snapshot report' ,
855
862
values : [ { label : 'Difference:' , formatted : ' {\n- foo: \'not bar\',\n+ foo: \'bar\',\n }' } ]
856
863
} ) ;
857
864
858
865
{
859
- const executionContext = setup ( 'fails' ) ;
866
+ const testInstance = setup ( 'fails' ) ;
860
867
if ( updating ) {
861
- assertions . snapshot . call ( executionContext , { foo : 'bar' } , 'my message' ) ;
868
+ assertions . snapshot . call ( testInstance , { foo : 'bar' } , 'my message' ) ;
862
869
} else {
863
870
failsWith ( t , ( ) => {
864
- assertions . snapshot . call ( executionContext , { foo : 'not bar' } , 'my message' ) ;
871
+ assertions . snapshot . call ( testInstance , { foo : 'not bar' } , 'my message' ) ;
865
872
} , {
866
873
assertion : 'snapshot' ,
867
874
message : 'my message' ,
@@ -871,23 +878,23 @@ test('.snapshot()', t => {
871
878
}
872
879
873
880
{
874
- const executionContext = setup ( 'rendered comparison' ) ;
881
+ const testInstance = setup ( 'rendered comparison' ) ;
875
882
if ( updating ) {
876
- assertions . snapshot . call ( executionContext , renderer . create ( React . createElement ( HelloMessage , { name : 'Sindre' } ) ) . toJSON ( ) ) ;
883
+ assertions . snapshot . call ( testInstance , renderer . create ( React . createElement ( HelloMessage , { name : 'Sindre' } ) ) . toJSON ( ) ) ;
877
884
} else {
878
885
passes ( t , ( ) => {
879
- assertions . snapshot . call ( executionContext , React . createElement ( 'div' , null , 'Hello ' , React . createElement ( 'mark' , null , 'Sindre' ) ) ) ;
886
+ assertions . snapshot . call ( testInstance , React . createElement ( 'div' , null , 'Hello ' , React . createElement ( 'mark' , null , 'Sindre' ) ) ) ;
880
887
} ) ;
881
888
}
882
889
}
883
890
884
891
{
885
- const executionContext = setup ( 'rendered comparison' ) ;
892
+ const testInstance = setup ( 'rendered comparison' ) ;
886
893
if ( updating ) {
887
- assertions . snapshot . call ( executionContext , renderer . create ( React . createElement ( HelloMessage , { name : 'Sindre' } ) ) . toJSON ( ) ) ;
894
+ assertions . snapshot . call ( testInstance , renderer . create ( React . createElement ( HelloMessage , { name : 'Sindre' } ) ) . toJSON ( ) ) ;
888
895
} else {
889
896
failsWith ( t , ( ) => {
890
- assertions . snapshot . call ( executionContext , renderer . create ( React . createElement ( HelloMessage , { name : 'Vadim' } ) ) . toJSON ( ) ) ;
897
+ assertions . snapshot . call ( testInstance , renderer . create ( React . createElement ( HelloMessage , { name : 'Vadim' } ) ) . toJSON ( ) ) ;
891
898
} , {
892
899
assertion : 'snapshot' ,
893
900
message : 'Did not match snapshot' ,
@@ -897,12 +904,12 @@ test('.snapshot()', t => {
897
904
}
898
905
899
906
{
900
- const executionContext = setup ( 'element comparison' ) ;
907
+ const testInstance = setup ( 'element comparison' ) ;
901
908
if ( updating ) {
902
- assertions . snapshot . call ( executionContext , React . createElement ( HelloMessage , { name : 'Sindre' } ) ) ;
909
+ assertions . snapshot . call ( testInstance , React . createElement ( HelloMessage , { name : 'Sindre' } ) ) ;
903
910
} else {
904
911
failsWith ( t , ( ) => {
905
- assertions . snapshot . call ( executionContext , React . createElement ( HelloMessage , { name : 'Vadim' } ) ) ;
912
+ assertions . snapshot . call ( testInstance , React . createElement ( HelloMessage , { name : 'Vadim' } ) ) ;
906
913
} , {
907
914
assertion : 'snapshot' ,
908
915
message : 'Did not match snapshot' ,
0 commit comments