@@ -9,6 +9,12 @@ const fetch = require('node-fetch');
9
9
run ( 'production' ) ;
10
10
run ( 'development' ) ;
11
11
12
+ Nightmare . action ( 'page' , {
13
+ title ( done ) {
14
+ this . evaluate_now ( ( ) => document . querySelector ( 'h1' ) . textContent , done ) ;
15
+ }
16
+ } ) ;
17
+
12
18
function run ( env ) {
13
19
describe ( `env=${ env } ` , function ( ) {
14
20
this . timeout ( 20000 ) ;
@@ -150,55 +156,38 @@ function run(env) {
150
156
} ) ;
151
157
152
158
it ( 'serves /' , ( ) => {
153
- return nightmare
154
- . goto ( base )
155
- . evaluate ( ( ) => document . querySelector ( 'h1' ) . textContent )
156
- . then ( title => {
157
- assert . equal ( title , 'Great success!' ) ;
158
- } ) ;
159
+ return nightmare . goto ( base ) . page . title ( ) . then ( title => {
160
+ assert . equal ( title , 'Great success!' ) ;
161
+ } ) ;
159
162
} ) ;
160
163
161
164
it ( 'serves static route' , ( ) => {
162
- return nightmare
163
- . goto ( `${ base } /about` )
164
- . evaluate ( ( ) => document . querySelector ( 'h1' ) . textContent )
165
- . then ( title => {
166
- assert . equal ( title , 'About this site' ) ;
167
- } ) ;
165
+ return nightmare . goto ( `${ base } /about` ) . page . title ( ) . then ( title => {
166
+ assert . equal ( title , 'About this site' ) ;
167
+ } ) ;
168
168
} ) ;
169
169
170
170
it ( 'serves dynamic route' , ( ) => {
171
- return nightmare
172
- . goto ( `${ base } /blog/what-is-sapper` )
173
- . evaluate ( ( ) => document . querySelector ( 'h1' ) . textContent )
174
- . then ( title => {
175
- assert . equal ( title , 'What is Sapper?' ) ;
176
- } ) ;
171
+ return nightmare . goto ( `${ base } /blog/what-is-sapper` ) . page . title ( ) . then ( title => {
172
+ assert . equal ( title , 'What is Sapper?' ) ;
173
+ } ) ;
177
174
} ) ;
178
175
179
176
it ( 'navigates to a new page without reloading' , ( ) => {
180
- let requests ;
181
- return nightmare
182
- . goto ( base ) . wait ( ( ) => window . READY ) . wait ( 200 )
177
+ return nightmare . goto ( base ) . wait ( ( ) => window . READY ) . wait ( 200 )
183
178
. then ( ( ) => {
184
- return capture ( ( ) => {
185
- return nightmare . click ( 'a[href="/about"]' ) ;
186
- } ) ;
179
+ return capture ( ( ) => nightmare . click ( 'a[href="/about"]' ) ) ;
187
180
} )
188
- . then ( reqs => {
189
- requests = reqs ;
190
-
181
+ . then ( requests => {
182
+ assert . deepEqual ( requests . map ( r => r . url ) , [ ] ) ;
191
183
return nightmare . path ( ) ;
192
184
} )
193
185
. then ( path => {
194
186
assert . equal ( path , '/about' ) ;
195
-
196
- return nightmare . evaluate ( ( ) => document . title ) ;
187
+ return nightmare . title ( ) ;
197
188
} )
198
189
. then ( title => {
199
190
assert . equal ( title , 'About' ) ;
200
-
201
- assert . deepEqual ( requests . map ( r => r . url ) , [ ] ) ;
202
191
} ) ;
203
192
} ) ;
204
193
@@ -209,7 +198,7 @@ function run(env) {
209
198
. click ( '.goto' )
210
199
. wait ( ( ) => window . location . pathname === '/blog/what-is-sapper' )
211
200
. wait ( 100 )
212
- . then ( ( ) => nightmare . evaluate ( ( ) => document . title ) )
201
+ . title ( )
213
202
. then ( title => {
214
203
assert . equal ( title , 'What is Sapper?' ) ;
215
204
} ) ;
@@ -281,47 +270,31 @@ function run(env) {
281
270
. then ( ( ) => nightmare . path ( ) )
282
271
. then ( path => {
283
272
assert . equal ( path , '/about' ) ;
284
-
285
- return nightmare . evaluate ( ( ) => document . querySelector ( 'h1' ) . textContent ) ;
273
+ return nightmare . title ( ) ;
286
274
} )
287
- . then ( header_text => {
288
- assert . equal ( header_text , 'About this site' ) ;
289
-
275
+ . then ( title => {
276
+ assert . equal ( title , 'About' ) ;
290
277
return nightmare . evaluate ( ( ) => window . fulfil ( { } ) ) . wait ( 100 ) ;
291
278
} )
292
279
. then ( ( ) => nightmare . path ( ) )
293
280
. then ( path => {
294
281
assert . equal ( path , '/about' ) ;
295
-
296
- return nightmare . evaluate ( ( ) => document . querySelector ( 'h1' ) . textContent ) ;
282
+ return nightmare . title ( ) ;
297
283
} )
298
- . then ( header_text => {
299
- assert . equal ( header_text , 'About this site' ) ;
300
-
301
- return nightmare . evaluate ( ( ) => window . fulfil ( { } ) ) . wait ( 100 ) ;
284
+ . then ( title => {
285
+ assert . equal ( title , 'About' ) ;
302
286
} ) ;
303
287
} ) ;
304
288
305
289
it ( 'passes entire request object to preload' , ( ) => {
306
290
return nightmare
307
291
. goto ( `${ base } /show-url` )
292
+ . wait ( ( ) => window . READY )
308
293
. evaluate ( ( ) => document . querySelector ( 'p' ) . innerHTML )
309
- . then ( html => {
294
+ . end ( ) . then ( html => {
310
295
assert . equal ( html , `URL is /show-url` ) ;
311
296
} ) ;
312
297
} ) ;
313
-
314
- it ( 'calls a delete handler' , ( ) => {
315
- return nightmare
316
- . goto ( `${ base } /delete-test` )
317
- . wait ( ( ) => window . READY )
318
- . click ( '.del' )
319
- . wait ( ( ) => window . deleted )
320
- . evaluate ( ( ) => window . deleted . id )
321
- . then ( id => {
322
- assert . equal ( id , 42 ) ;
323
- } ) ;
324
- } ) ;
325
298
} ) ;
326
299
327
300
describe ( 'headers' , ( ) => {
@@ -355,4 +328,4 @@ function exec(cmd) {
355
328
fulfil ( ) ;
356
329
} ) ;
357
330
} ) ;
358
- }
331
+ }
0 commit comments