@@ -54,10 +54,19 @@ type DetailsSpec = {
54
54
[ key in keyof typeof JSON_SCHEMA [ 'properties' ] ] ?: string [ ] ;
55
55
}
56
56
57
- const testWholeWebsiteDetails = ( jsonAnswer : any , expectedWebsiteDetails : DetailsSpec ) => {
57
+ const testWholeWebsiteDetails = ( jsonAnswer : any , expectedWebsiteDetails : DetailsSpec , pageContent : string ) => {
58
58
for ( const [ key , urls ] of Object . entries ( expectedWebsiteDetails ) ) {
59
59
testURLInclusion ( key as keyof typeof JSON_SCHEMA [ 'properties' ] , urls as string [ ] , jsonAnswer ) ;
60
60
}
61
+ for ( const [ , items ] of Object . entries ( jsonAnswer ) as [
62
+ string ,
63
+ { item : string , description : string } [ ] ,
64
+ ] [ ] ) {
65
+ for ( const item of items ) {
66
+ // avoid hallucinations by ensuring that every returned item is in the page content
67
+ expect ( pageContent ) . toContain ( item . item ) ;
68
+ }
69
+ }
61
70
} ;
62
71
63
72
const testWebsite = async ( url : string , spec : DetailsSpec ) => {
@@ -75,7 +84,7 @@ const testWebsite = async (url: string, spec: DetailsSpec) => {
75
84
} ) ;
76
85
const { jsonAnswer } = answerResult ;
77
86
expect ( jsonAnswer ) . not . toBeNull ( ) ;
78
- testWholeWebsiteDetails ( jsonAnswer , spec ) ;
87
+ testWholeWebsiteDetails ( jsonAnswer , spec , pageContent ) ;
79
88
} ;
80
89
81
90
test ( 'Scrapes contacts from https://unbounce.com/contact-us/' , async ( ) => testWebsite ( 'https://unbounce.com/contact-us/' , {
0 commit comments