@@ -13,6 +13,7 @@ import {
1313 toRespondWith ,
1414 toRespondWithError ,
1515 toSendNotification ,
16+ toTrace ,
1617 toTrackError ,
1718 toTrackEvent ,
1819} from './matchers' ;
@@ -29,6 +30,7 @@ expect.extend({
2930 toRender,
3031 toTrackError,
3132 toTrackEvent,
33+ toTrace,
3234} ) ;
3335
3436describe ( 'toRespondWith' , ( ) => {
@@ -949,3 +951,166 @@ describe('toTrackEvent', () => {
949951 } ) ;
950952 } ) ;
951953} ) ;
954+
955+ describe ( 'toTrace' , ( ) => {
956+ it ( 'passes when the trace is correct' , ( ) => {
957+ expect (
958+ getMockResponse ( {
959+ tracked : {
960+ traces : [
961+ {
962+ id : '1' ,
963+ name : 'foo' ,
964+ parentContext : { bar : 'baz' } ,
965+ startTime : 1234567890 ,
966+ data : { qux : 'quux' } ,
967+ tags : { corge : 'grault' } ,
968+ } ,
969+ ] ,
970+ } ,
971+ } ) ,
972+ ) . toTrace ( {
973+ id : '1' ,
974+ name : 'foo' ,
975+ parentContext : { bar : 'baz' } ,
976+ startTime : 1234567890 ,
977+ data : { qux : 'quux' } ,
978+ tags : { corge : 'grault' } ,
979+ } ) ;
980+ } ) ;
981+
982+ it ( 'passes when the partial trace is correct' , ( ) => {
983+ expect (
984+ getMockResponse ( {
985+ tracked : {
986+ traces : [
987+ {
988+ id : '1' ,
989+ name : 'foo' ,
990+ parentContext : { bar : 'baz' } ,
991+ startTime : 1234567890 ,
992+ } ,
993+ ] ,
994+ } ,
995+ } ) ,
996+ ) . toTrace ( {
997+ id : '1' ,
998+ name : 'foo' ,
999+ parentContext : { bar : 'baz' } ,
1000+ startTime : 1234567890 ,
1001+ } ) ;
1002+ } ) ;
1003+
1004+ it ( 'passes when any trace is tracked' , ( ) => {
1005+ expect (
1006+ getMockResponse ( {
1007+ tracked : {
1008+ traces : [
1009+ {
1010+ id : '1' ,
1011+ name : 'foo' ,
1012+ parentContext : { bar : 'baz' } ,
1013+ startTime : 1234567890 ,
1014+ data : { qux : 'quux' } ,
1015+ tags : { corge : 'grault' } ,
1016+ } ,
1017+ ] ,
1018+ } ,
1019+ } ) ,
1020+ ) . toTrace ( ) ;
1021+ } ) ;
1022+
1023+ it ( 'fails when the trace is incorrect' , ( ) => {
1024+ expect ( ( ) =>
1025+ expect (
1026+ getMockResponse ( {
1027+ tracked : {
1028+ traces : [
1029+ {
1030+ id : '1' ,
1031+ name : 'foo' ,
1032+ parentContext : { bar : 'baz' } ,
1033+ startTime : 1234567890 ,
1034+ data : { qux : 'quux' } ,
1035+ tags : { corge : 'grault' } ,
1036+ } ,
1037+ ] ,
1038+ } ,
1039+ } ) ,
1040+ ) . toTrace ( {
1041+ id : '2' ,
1042+ name : 'foo' ,
1043+ parentContext : { bar : 'baz' } ,
1044+ startTime : 1234567890 ,
1045+ data : { qux : 'quux' } ,
1046+ tags : { corge : 'grault' } ,
1047+ } ) ,
1048+ ) . toThrow ( 'Received' ) ;
1049+ } ) ;
1050+
1051+ describe ( 'not' , ( ) => {
1052+ it ( 'passes when the trace does not match' , ( ) => {
1053+ expect (
1054+ getMockResponse ( {
1055+ tracked : {
1056+ traces : [
1057+ {
1058+ id : '1' ,
1059+ name : 'foo' ,
1060+ parentContext : { bar : 'baz' } ,
1061+ startTime : 1234567890 ,
1062+ data : { qux : 'quux' } ,
1063+ tags : { corge : 'grault' } ,
1064+ } ,
1065+ ] ,
1066+ } ,
1067+ } ) ,
1068+ ) . not . toTrace ( {
1069+ id : '2' ,
1070+ name : 'foo' ,
1071+ parentContext : { bar : 'baz' } ,
1072+ startTime : 1234567890 ,
1073+ data : { qux : 'quux' } ,
1074+ tags : { corge : 'grault' } ,
1075+ } ) ;
1076+ } ) ;
1077+
1078+ it ( 'passes when there are no traces' , ( ) => {
1079+ expect (
1080+ getMockResponse ( {
1081+ tracked : {
1082+ traces : [ ] ,
1083+ } ,
1084+ } ) ,
1085+ ) . not . toTrace ( ) ;
1086+ } ) ;
1087+
1088+ it ( 'fails when the trace matches' , ( ) => {
1089+ expect ( ( ) =>
1090+ expect (
1091+ getMockResponse ( {
1092+ tracked : {
1093+ traces : [
1094+ {
1095+ id : '1' ,
1096+ name : 'foo' ,
1097+ parentContext : { bar : 'baz' } ,
1098+ startTime : 1234567890 ,
1099+ data : { qux : 'quux' } ,
1100+ tags : { corge : 'grault' } ,
1101+ } ,
1102+ ] ,
1103+ } ,
1104+ } ) ,
1105+ ) . not . toTrace ( {
1106+ id : '1' ,
1107+ name : 'foo' ,
1108+ parentContext : { bar : 'baz' } ,
1109+ startTime : 1234567890 ,
1110+ data : { qux : 'quux' } ,
1111+ tags : { corge : 'grault' } ,
1112+ } ) ,
1113+ ) . toThrow ( 'Expected not to trace with data' ) ;
1114+ } ) ;
1115+ } ) ;
1116+ } ) ;
0 commit comments