@@ -29,9 +29,7 @@ describe('Snippet Browser test', () => {
2929 } ,
3030 ] )
3131 const snippeted = response . results [ 0 ] ?. hits [ 0 ] ?. _highlightResult
32- expect ( snippeted . overview . value ) . toEqual ( 'Princess' )
33- const resKeys = Object . keys ( snippeted )
34- expect ( resKeys ) . toEqual ( expect . arrayContaining ( Object . keys ( dataset [ 0 ] ) ) )
32+ expect ( snippeted ?. overview ?. value ) . toEqual ( 'Princess' )
3533 } )
3634
3735 test ( 'Test one attributesToSnippet on specific query' , async ( ) => {
@@ -47,11 +45,8 @@ describe('Snippet Browser test', () => {
4745 ] )
4846 const highlighted = response . results [ 0 ] ?. hits [ 0 ] ?. _highlightResult
4947 const snippeted = response . results [ 0 ] . hits [ 0 ] . _snippetResult
50- expect ( highlighted . overview . value ) . toEqual ( 'While' )
51- expect ( snippeted . overview . value ) . toEqual ( 'While...' )
52- const resKeys = Object . keys ( response . results [ 0 ] ?. hits [ 0 ] ?. _highlightResult )
53-
54- expect ( resKeys ) . toEqual ( expect . arrayContaining ( Object . keys ( dataset [ 0 ] ) ) )
48+ expect ( highlighted ?. overview ?. value ) . toEqual ( 'While' )
49+ expect ( snippeted ?. overview ?. value ) . toEqual ( 'While...' )
5550 } )
5651
5752 test ( 'Test two attributesToSnippet on specific query with one hit empty string' , async ( ) => {
@@ -71,24 +66,21 @@ describe('Snippet Browser test', () => {
7166 const firstHitHighlight = response . results [ 0 ] ?. hits [ 0 ] ?. _highlightResult
7267 const firstHitSnippet = response . results [ 0 ] . hits [ 0 ] . _snippetResult
7368
74- expect ( firstHitHighlight . title . value ) . toEqual ( '<p>S</p>tar Wars' )
75- expect ( firstHitHighlight . overview . value ) . toEqual (
69+ expect ( firstHitHighlight ? .title ? .value ) . toEqual ( '<p>S</p>tar Wars' )
70+ expect ( firstHitHighlight ? .overview ? .value ) . toEqual (
7671 'Luke <p>S</p>kywalker and'
7772 )
78- expect ( firstHitSnippet . title . value ) . toEqual ( '<p>S</p>tar Wars...' )
79- expect ( firstHitSnippet . overview . value ) . toEqual (
73+ expect ( firstHitSnippet ? .title ? .value ) . toEqual ( '<p>S</p>tar Wars...' )
74+ expect ( firstHitSnippet ? .overview ? .value ) . toEqual (
8075 'Luke <p>S</p>kywalker and...'
8176 )
8277
8378 const secondHitHighlight = response . results [ 0 ] ?. hits [ 1 ] ?. _highlightResult
8479 const secondHitSnippet = response . results [ 0 ] ?. hits [ 1 ] ?. _snippetResult
85- expect ( secondHitHighlight . title . value ) . toEqual ( 'Four' )
86- expect ( secondHitHighlight . overview . value ) . toEqual ( "It'<p>s</p> Ted" )
87- expect ( secondHitSnippet . title . value ) . toEqual ( 'Four...' )
88- expect ( secondHitSnippet . overview . value ) . toEqual ( "It'<p>s</p> Ted..." )
89-
90- const resKeys = Object . keys ( response . results [ 0 ] ?. hits [ 0 ] ?. _highlightResult )
91- expect ( resKeys ) . toEqual ( expect . arrayContaining ( Object . keys ( dataset [ 0 ] ) ) )
80+ expect ( secondHitHighlight ?. title ?. value ) . toEqual ( 'Four' )
81+ expect ( secondHitHighlight ?. overview ?. value ) . toEqual ( "It'<p>s</p> Ted" )
82+ expect ( secondHitSnippet ?. title ?. value ) . toEqual ( 'Four...' )
83+ expect ( secondHitSnippet ?. overview ?. value ) . toEqual ( "It'<p>s</p> Ted..." )
9284 } )
9385
9486 test ( 'Test attributesToSnippet on a null attribute' , async ( ) => {
@@ -103,10 +95,7 @@ describe('Snippet Browser test', () => {
10395 ] )
10496
10597 const firstHit = response . results [ 0 ] ?. hits [ 0 ] ?. _highlightResult
106- expect ( firstHit . overview . value ) . toEqual ( 'null' )
107-
108- const resKeys = Object . keys ( response . results [ 0 ] ?. hits [ 0 ] ?. _highlightResult )
109- expect ( resKeys ) . toEqual ( expect . arrayContaining ( Object . keys ( dataset [ 0 ] ) ) )
98+ expect ( firstHit ?. overview ?. value ) . toEqual ( 'null' )
11099 } )
111100
112101 test ( 'Test one attributesToSnippet on placeholder w/ snippetEllipsisText' , async ( ) => {
@@ -120,9 +109,7 @@ describe('Snippet Browser test', () => {
120109 } ,
121110 ] )
122111 const snippeted = response . results [ 0 ] ?. hits [ 0 ] ?. _highlightResult
123- expect ( snippeted . overview . value ) . toEqual ( 'Princess' )
124- const resKeys = Object . keys ( snippeted )
125- expect ( resKeys ) . toEqual ( expect . arrayContaining ( Object . keys ( dataset [ 0 ] ) ) )
112+ expect ( snippeted ?. overview ?. value ) . toEqual ( 'Princess' )
126113 } )
127114
128115 test ( 'Test one attributesToSnippet on specific query w/ snippetEllipsisText' , async ( ) => {
@@ -136,9 +123,7 @@ describe('Snippet Browser test', () => {
136123 } ,
137124 ] )
138125 const snippeted = response . results [ 0 ] ?. hits [ 0 ] ?. _highlightResult ?. overview
139- expect ( snippeted . value ) . toEqual ( 'While' )
140- const resKeys = Object . keys ( response . results [ 0 ] ?. hits [ 0 ] ?. _highlightResult )
141- expect ( resKeys ) . toEqual ( expect . arrayContaining ( Object . keys ( dataset [ 0 ] ) ) )
126+ expect ( snippeted ?. value ) . toEqual ( 'While' )
142127 } )
143128
144129 test ( 'Test two attributesToSnippet on specific query with one hit empty string w/ snippetEllipsisText' , async ( ) => {
@@ -153,20 +138,17 @@ describe('Snippet Browser test', () => {
153138 ] )
154139 const firstHit = response . results [ 0 ] ?. hits [ 0 ] ?. _highlightResult
155140
156- expect ( firstHit . title . value ) . toEqual (
141+ expect ( firstHit ? .title ? .value ) . toEqual (
157142 '__ais-highlight__S__/ais-highlight__tar Wars'
158143 )
159- expect ( firstHit . overview . value ) . toEqual (
144+ expect ( firstHit ? .overview ? .value ) . toEqual (
160145 'Luke __ais-highlight__S__/ais-highlight__kywalker and'
161146 )
162147 const secondHit = response . results [ 0 ] . hits [ 1 ] . _highlightResult
163- expect ( secondHit . title . value ) . toEqual ( 'Four' )
164- expect ( secondHit . overview . value ) . toEqual (
148+ expect ( secondHit ? .title ? .value ) . toEqual ( 'Four' )
149+ expect ( secondHit ? .overview ? .value ) . toEqual (
165150 "It'__ais-highlight__s__/ais-highlight__ Ted"
166151 )
167-
168- const resKeys = Object . keys ( response . results [ 0 ] ?. hits [ 0 ] ?. _highlightResult )
169- expect ( resKeys ) . toEqual ( expect . arrayContaining ( Object . keys ( dataset [ 0 ] ) ) )
170152 } )
171153
172154 test ( 'Test attributesToSnippet on a null attribute w/ snippetEllipsisText' , async ( ) => {
@@ -181,8 +163,23 @@ describe('Snippet Browser test', () => {
181163 ] )
182164
183165 const firstHit = response . results [ 0 ] ?. hits [ 0 ] ?. _highlightResult
184- expect ( firstHit . overview . value ) . toEqual ( 'null' )
185- const resKeys = Object . keys ( response . results [ 0 ] ?. hits [ 0 ] ?. _highlightResult )
186- expect ( resKeys ) . toEqual ( expect . arrayContaining ( Object . keys ( dataset [ 0 ] ) ) )
166+ expect ( firstHit ?. overview ?. value ) . toEqual ( 'null' )
167+ expect ( response . results [ 0 ] ?. hits [ 0 ] ?. _highlightResult ) . toHaveProperty ( 'id' )
168+ expect ( response . results [ 0 ] ?. hits [ 0 ] ?. _highlightResult ) . toHaveProperty (
169+ 'title'
170+ )
171+ expect ( response . results [ 0 ] ?. hits [ 0 ] ?. _highlightResult ) . toHaveProperty (
172+ 'overview'
173+ )
174+ expect ( response . results [ 0 ] ?. hits [ 0 ] ?. _highlightResult ) . toHaveProperty (
175+ 'genres'
176+ )
177+ expect ( response . results [ 0 ] ?. hits [ 0 ] ?. _highlightResult ) . toHaveProperty (
178+ 'poster'
179+ )
180+ expect ( response . results [ 0 ] ?. hits [ 0 ] ?. _highlightResult ) . toHaveProperty (
181+ 'release_date'
182+ )
183+ // expect(resKeys).toEqual(expect.arrayContaining(Object.keys(dataset[0])))
187184 } )
188185} )
0 commit comments