1Test::Mojo(3) User Contributed Perl Documentation Test::Mojo(3)
2
3
4
6 Test::Mojo - Testing Mojo
7
9 use Test::More;
10 use Test::Mojo;
11
12 my $t = Test::Mojo->new('MyApp');
13
14 # HTML/XML
15 $t->get_ok('/welcome')->status_is(200)->text_is('div#message' => 'Hello!');
16
17 # JSON
18 $t->post_ok('/search.json' => form => {q => 'Perl'})
19 ->status_is(200)
20 ->header_is('Server' => 'Mojolicious (Perl)')
21 ->header_isnt('X-Bender' => 'Bite my shiny metal ass!')
22 ->json_is('/results/4/title' => 'Perl rocks!')
23 ->json_like('/results/7/title' => qr/Perl/);
24
25 # WebSocket
26 $t->websocket_ok('/echo')
27 ->send_ok('hello')
28 ->message_ok
29 ->message_is('echo: hello')
30 ->finish_ok;
31
32 done_testing();
33
35 Test::Mojo is a test user agent based on Mojo::UserAgent, it is usually
36 used together with Test::More to test Mojolicious applications. Just
37 run your tests with prove.
38
39 $ prove -l -v
40 $ prove -l -v t/foo.t
41
42 If it is not already defined, the "MOJO_LOG_LEVEL" environment variable
43 will be set to "debug" or "fatal", depending on the value of the
44 "HARNESS_IS_VERBOSE" environment variable. And to make it esier to test
45 HTTPS/WSS web services "insecure" in Mojo::UserAgent will be activated
46 by default for "ua".
47
48 See Mojolicious::Guides::Testing for more.
49
51 Test::Mojo implements the following attributes.
52
53 handler
54 my $cb = $t->handler;
55 $t = $t->handler(sub {...});
56
57 A callback to connect Test::Mojo with Test::More.
58
59 $t->handler(sub {
60 my ($name, @args) = @_;
61 return Test::More->can($name)->(@args);
62 });
63
64 message
65 my $msg = $t->message;
66 $t = $t->message([text => $bytes]);
67
68 Current WebSocket message represented as an array reference containing
69 the frame type and payload.
70
71 # More specific tests
72 use Mojo::JSON qw(decode_json);
73 my $hash = decode_json $t->message->[1];
74 is ref $hash, 'HASH', 'right reference';
75 is $hash->{foo}, 'bar', 'right value';
76
77 # Test custom message
78 $t->message([binary => $bytes])
79 ->json_message_has('/foo/bar')
80 ->json_message_hasnt('/bar')
81 ->json_message_is('/foo/baz' => {yada => [1, 2, 3]});
82
83 success
84 my $bool = $t->success;
85 $t = $t->success($bool);
86
87 True if the last test was successful.
88
89 # Build custom tests
90 my $location_is = sub {
91 my ($t, $value, $desc) = @_;
92 $desc ||= "Location: $value";
93 local $Test::Builder::Level = $Test::Builder::Level + 1;
94 return $t->success(is($t->tx->res->headers->location, $value, $desc));
95 };
96 $t->get_ok('/')
97 ->status_is(302)
98 ->$location_is('https://mojolicious.org')
99 ->or(sub { diag 'Must have been Joel!' });
100
101 tx
102 my $tx = $t->tx;
103 $t = $t->tx(Mojo::Transaction::HTTP->new);
104
105 Current transaction, usually a Mojo::Transaction::HTTP or
106 Mojo::Transaction::WebSocket object.
107
108 # More specific tests
109 is $t->tx->res->json->{foo}, 'bar', 'right value';
110 ok $t->tx->res->content->is_multipart, 'multipart content';
111 is $t->tx->previous->res->code, 302, 'right status';
112
113 ua
114 my $ua = $t->ua;
115 $t = $t->ua(Mojo::UserAgent->new);
116
117 User agent used for testing, defaults to a Mojo::UserAgent object.
118
119 # Allow redirects
120 $t->ua->max_redirects(10);
121 $t->get_ok('/redirect')->status_is(200)->content_like(qr/redirected/);
122
123 # Switch protocol from HTTP to HTTPS
124 $t->ua->server->url('https');
125 $t->get_ok('/secure')->status_is(200)->content_like(qr/secure/);
126
127 # Use absolute URL for request with Basic authentication
128 my $url = $t->ua->server->url->userinfo('sri:secr3t')->path('/secrets.json');
129 $t->post_ok($url => json => {limit => 10})
130 ->status_is(200)
131 ->json_is('/1/content', 'Mojo rocks!');
132
133 # Customize all transactions (including followed redirects)
134 $t->ua->on(start => sub {
135 my ($ua, $tx) = @_;
136 $tx->req->headers->accept_language('en-US');
137 });
138 $t->get_ok('/hello')->status_is(200)->content_like(qr/Howdy/);
139
141 Test::Mojo inherits all methods from Mojo::Base and implements the
142 following new ones.
143
144 app
145 my $app = $t->app;
146 $t = $t->app(Mojolicious->new);
147
148 Access application with "app" in Mojo::UserAgent::Server.
149
150 # Change log level
151 $t->app->log->level('fatal');
152
153 # Test application directly
154 is $t->app->defaults->{foo}, 'bar', 'right value';
155 ok $t->app->routes->find('echo')->is_websocket, 'WebSocket route';
156 my $c = $t->app->build_controller;
157 ok $c->render(template => 'foo'), 'rendering was successful';
158 is $c->res->status, 200, 'right status';
159 is $c->res->body, 'Foo!', 'right content';
160
161 # Change application behavior
162 $t->app->hook(before_dispatch => sub {
163 my $c = shift;
164 $c->render(text => 'This request did not reach the router.')
165 if $c->req->url->path->contains('/user');
166 });
167 $t->get_ok('/user')->status_is(200)->content_like(qr/not reach the router/);
168
169 # Extract additional information
170 my $stash;
171 $t->app->hook(after_dispatch => sub { $stash = shift->stash });
172 $t->get_ok('/hello')->status_is(200);
173 is $stash->{foo}, 'bar', 'right value';
174
175 attr_is
176 $t = $t->attr_is('img.cat', 'alt', 'Grumpy cat');
177 $t = $t->attr_is('img.cat', 'alt', 'Grumpy cat', 'right alt text');
178
179 Checks text content of attribute with "attr" in Mojo::DOM at the CSS
180 selectors first matching HTML/XML element for exact match with "at" in
181 Mojo::DOM.
182
183 attr_isnt
184 $t = $t->attr_isnt('img.cat', 'alt', 'Calm cat');
185 $t = $t->attr_isnt('img.cat', 'alt', 'Calm cat', 'different alt text');
186
187 Opposite of "attr_is".
188
189 attr_like
190 $t = $t->attr_like('img.cat', 'alt', qr/Grumpy/);
191 $t = $t->attr_like('img.cat', 'alt', qr/Grumpy/, 'right alt text');
192
193 Checks text content of attribute with "attr" in Mojo::DOM at the CSS
194 selectors first matching HTML/XML element for similar match with "at"
195 in Mojo::DOM.
196
197 attr_unlike
198 $t = $t->attr_unlike('img.cat', 'alt', qr/Calm/);
199 $t = $t->attr_unlike('img.cat', 'alt', qr/Calm/, 'different alt text');
200
201 Opposite of "attr_like".
202
203 content_is
204 $t = $t->content_is('working!');
205 $t = $t->content_is('working!', 'right content');
206
207 Check response content for exact match after retrieving it from "text"
208 in Mojo::Message.
209
210 content_isnt
211 $t = $t->content_isnt('working!');
212 $t = $t->content_isnt('working!', 'different content');
213
214 Opposite of "content_is".
215
216 content_like
217 $t = $t->content_like(qr/working!/);
218 $t = $t->content_like(qr/working!/, 'right content');
219
220 Check response content for similar match after retrieving it from
221 "text" in Mojo::Message.
222
223 content_type_is
224 $t = $t->content_type_is('text/html');
225 $t = $t->content_type_is('text/html', 'right content type');
226
227 Check response "Content-Type" header for exact match.
228
229 content_type_isnt
230 $t = $t->content_type_isnt('text/html');
231 $t = $t->content_type_isnt('text/html', 'different content type');
232
233 Opposite of "content_type_is".
234
235 content_type_like
236 $t = $t->content_type_like(qr/text/);
237 $t = $t->content_type_like(qr/text/, 'right content type');
238
239 Check response "Content-Type" header for similar match.
240
241 content_type_unlike
242 $t = $t->content_type_unlike(qr/text/);
243 $t = $t->content_type_unlike(qr/text/, 'different content type');
244
245 Opposite of "content_type_like".
246
247 content_unlike
248 $t = $t->content_unlike(qr/working!/);
249 $t = $t->content_unlike(qr/working!/, 'different content');
250
251 Opposite of "content_like".
252
253 delete_ok
254 $t = $t->delete_ok('http://example.com/foo');
255 $t = $t->delete_ok('/foo');
256 $t = $t->delete_ok('/foo' => {Accept => '*/*'} => 'Content!');
257 $t = $t->delete_ok('/foo' => {Accept => '*/*'} => form => {a => 'b'});
258 $t = $t->delete_ok('/foo' => {Accept => '*/*'} => json => {a => 'b'});
259
260 Perform a "DELETE" request and check for transport errors, takes the
261 same arguments as "delete" in Mojo::UserAgent, except for the callback.
262
263 element_count_is
264 $t = $t->element_count_is('div.foo[x=y]', 5);
265 $t = $t->element_count_is('html body div', 30, 'thirty elements');
266
267 Checks the number of HTML/XML elements matched by the CSS selector with
268 "find" in Mojo::DOM.
269
270 element_exists
271 $t = $t->element_exists('div.foo[x=y]');
272 $t = $t->element_exists('html head title', 'has a title');
273
274 Checks for existence of the CSS selectors first matching HTML/XML
275 element with "at" in Mojo::DOM.
276
277 # Check attribute values
278 $t->get_ok('/login')
279 ->element_exists('label[for=email]')
280 ->element_exists('input[name=email][type=text][value*="example.com"]')
281 ->element_exists('label[for=pass]')
282 ->element_exists('input[name=pass][type=password]')
283 ->element_exists('input[type=submit][value]');
284
285 element_exists_not
286 $t = $t->element_exists_not('div.foo[x=y]');
287 $t = $t->element_exists_not('html head title', 'has no title');
288
289 Opposite of "element_exists".
290
291 finish_ok
292 $t = $t->finish_ok;
293 $t = $t->finish_ok(1000);
294 $t = $t->finish_ok(1003 => 'Cannot accept data!');
295
296 Close WebSocket connection gracefully.
297
298 finished_ok
299 $t = $t->finished_ok(1000);
300
301 Wait for WebSocket connection to be closed gracefully and check status.
302
303 get_ok
304 $t = $t->get_ok('http://example.com/foo');
305 $t = $t->get_ok('/foo');
306 $t = $t->get_ok('/foo' => {Accept => '*/*'} => 'Content!');
307 $t = $t->get_ok('/foo' => {Accept => '*/*'} => form => {a => 'b'});
308 $t = $t->get_ok('/foo' => {Accept => '*/*'} => json => {a => 'b'});
309
310 Perform a "GET" request and check for transport errors, takes the same
311 arguments as "get" in Mojo::UserAgent, except for the callback.
312
313 # Run tests against remote host
314 $t->get_ok('https://mojolicious.org/perldoc')->status_is(200);
315
316 # Use relative URL for request with Basic authentication
317 $t->get_ok('//sri:secr3t@/secrets.json')
318 ->status_is(200)
319 ->json_is('/1/content', 'Mojo rocks!');
320
321 # Run additional tests on the transaction
322 $t->get_ok('/foo')->status_is(200);
323 is $t->tx->res->dom->at('input')->val, 'whatever', 'right value';
324
325 head_ok
326 $t = $t->head_ok('http://example.com/foo');
327 $t = $t->head_ok('/foo');
328 $t = $t->head_ok('/foo' => {Accept => '*/*'} => 'Content!');
329 $t = $t->head_ok('/foo' => {Accept => '*/*'} => form => {a => 'b'});
330 $t = $t->head_ok('/foo' => {Accept => '*/*'} => json => {a => 'b'});
331
332 Perform a "HEAD" request and check for transport errors, takes the same
333 arguments as "head" in Mojo::UserAgent, except for the callback.
334
335 header_exists
336 $t = $t->header_exists('ETag');
337 $t = $t->header_exists('ETag', 'header exists');
338
339 Check if response header exists.
340
341 header_exists_not
342 $t = $t->header_exists_not('ETag');
343 $t = $t->header_exists_not('ETag', 'header is missing');
344
345 Opposite of "header_exists".
346
347 header_is
348 $t = $t->header_is(ETag => '"abc321"');
349 $t = $t->header_is(ETag => '"abc321"', 'right header');
350
351 Check response header for exact match.
352
353 header_isnt
354 $t = $t->header_isnt(Etag => '"abc321"');
355 $t = $t->header_isnt(ETag => '"abc321"', 'different header');
356
357 Opposite of "header_is".
358
359 header_like
360 $t = $t->header_like(ETag => qr/abc/);
361 $t = $t->header_like(ETag => qr/abc/, 'right header');
362
363 Check response header for similar match.
364
365 header_unlike
366 $t = $t->header_unlike(ETag => qr/abc/);
367 $t = $t->header_unlike(ETag => qr/abc/, 'different header');
368
369 Opposite of "header_like".
370
371 json_has
372 $t = $t->json_has('/foo');
373 $t = $t->json_has('/minibar', 'has a minibar');
374
375 Check if JSON response contains a value that can be identified using
376 the given JSON Pointer with Mojo::JSON::Pointer.
377
378 json_hasnt
379 $t = $t->json_hasnt('/foo');
380 $t = $t->json_hasnt('/minibar', 'no minibar');
381
382 Opposite of "json_has".
383
384 json_is
385 $t = $t->json_is({foo => [1, 2, 3]});
386 $t = $t->json_is('/foo' => [1, 2, 3]);
387 $t = $t->json_is('/foo/1' => 2, 'right value');
388
389 Check the value extracted from JSON response using the given JSON
390 Pointer with Mojo::JSON::Pointer, which defaults to the root value if
391 it is omitted.
392
393 json_like
394 $t = $t->json_like('/foo/1' => qr/^\d+$/);
395 $t = $t->json_like('/foo/1' => qr/^\d+$/, 'right value');
396
397 Check the value extracted from JSON response using the given JSON
398 Pointer with Mojo::JSON::Pointer for similar match.
399
400 json_message_has
401 $t = $t->json_message_has('/foo');
402 $t = $t->json_message_has('/minibar', 'has a minibar');
403
404 Check if JSON WebSocket message contains a value that can be identified
405 using the given JSON Pointer with Mojo::JSON::Pointer.
406
407 json_message_hasnt
408 $t = $t->json_message_hasnt('/foo');
409 $t = $t->json_message_hasnt('/minibar', 'no minibar');
410
411 Opposite of "json_message_has".
412
413 json_message_is
414 $t = $t->json_message_is({foo => [1, 2, 3]});
415 $t = $t->json_message_is('/foo' => [1, 2, 3]);
416 $t = $t->json_message_is('/foo/1' => 2, 'right value');
417
418 Check the value extracted from JSON WebSocket message using the given
419 JSON Pointer with Mojo::JSON::Pointer, which defaults to the root value
420 if it is omitted.
421
422 json_message_like
423 $t = $t->json_message_like('/foo/1' => qr/^\d+$/);
424 $t = $t->json_message_like('/foo/1' => qr/^\d+$/, 'right value');
425
426 Check the value extracted from JSON WebSocket message using the given
427 JSON Pointer with Mojo::JSON::Pointer for similar match.
428
429 json_message_unlike
430 $t = $t->json_message_unlike('/foo/1' => qr/^\d+$/);
431 $t = $t->json_message_unlike('/foo/1' => qr/^\d+$/, 'different value');
432
433 Opposite of "json_message_like".
434
435 json_unlike
436 $t = $t->json_unlike('/foo/1' => qr/^\d+$/);
437 $t = $t->json_unlike('/foo/1' => qr/^\d+$/, 'different value');
438
439 Opposite of "json_like".
440
441 message_is
442 $t = $t->message_is({binary => $bytes});
443 $t = $t->message_is({text => $bytes});
444 $t = $t->message_is('working!');
445 $t = $t->message_is('working!', 'right message');
446
447 Check WebSocket message for exact match.
448
449 message_isnt
450 $t = $t->message_isnt({binary => $bytes});
451 $t = $t->message_isnt({text => $bytes});
452 $t = $t->message_isnt('working!');
453 $t = $t->message_isnt('working!', 'different message');
454
455 Opposite of "message_is".
456
457 message_like
458 $t = $t->message_like({binary => qr/$bytes/});
459 $t = $t->message_like({text => qr/$bytes/});
460 $t = $t->message_like(qr/working!/);
461 $t = $t->message_like(qr/working!/, 'right message');
462
463 Check WebSocket message for similar match.
464
465 message_ok
466 $t = $t->message_ok;
467 $t = $t->message_ok('got a message');
468
469 Wait for next WebSocket message to arrive.
470
471 # Wait for message and perform multiple tests on it
472 $t->websocket_ok('/time')
473 ->message_ok
474 ->message_like(qr/\d+/)
475 ->message_unlike(qr/\w+/)
476 ->finish_ok;
477
478 message_unlike
479 $t = $t->message_unlike({binary => qr/$bytes/});
480 $t = $t->message_unlike({text => qr/$bytes/});
481 $t = $t->message_unlike(qr/working!/);
482 $t = $t->message_unlike(qr/working!/, 'different message');
483
484 Opposite of "message_like".
485
486 new
487 my $t = Test::Mojo->new;
488 my $t = Test::Mojo->new('MyApp');
489 my $t = Test::Mojo->new('MyApp', {foo => 'bar'});
490 my $t = Test::Mojo->new(Mojo::File->new('/path/to/myapp.pl'));
491 my $t = Test::Mojo->new(Mojo::File->new('/path/to/myapp.pl'), {foo => 'bar'});
492 my $t = Test::Mojo->new(MyApp->new);
493 my $t = Test::Mojo->new(MyApp->new, {foo => 'bar'});
494
495 Construct a new Test::Mojo object. In addition to a class name or
496 Mojo::File object pointing to the application script, you can pass
497 along a hash reference with configuration values that will be used to
498 override the application configuration. The special configuration value
499 "config_override" will be set in "config" in Mojolicious as well, which
500 is used to disable configuration plugins like
501 Mojolicious::Plugin::Config, Mojolicious::Plugin::JSONConfig and
502 Mojolicious::Plugin::NotYAMLConfig for tests.
503
504 # Load application script relative to the "t" directory
505 use Mojo::File qw(curfile);
506 my $t = Test::Mojo->new(curfile->dirname->sibling('myapp.pl'));
507
508 options_ok
509 $t = $t->options_ok('http://example.com/foo');
510 $t = $t->options_ok('/foo');
511 $t = $t->options_ok('/foo' => {Accept => '*/*'} => 'Content!');
512 $t = $t->options_ok('/foo' => {Accept => '*/*'} => form => {a => 'b'});
513 $t = $t->options_ok('/foo' => {Accept => '*/*'} => json => {a => 'b'});
514
515 Perform a "OPTIONS" request and check for transport errors, takes the
516 same arguments as "options" in Mojo::UserAgent, except for the
517 callback.
518
519 or
520 $t = $t->or(sub {...});
521
522 Execute callback if the value of "success" is false.
523
524 # Diagnostics
525 $t->get_ok('/bad')->or(sub { diag 'Must have been Glen!' })
526 ->status_is(200)->or(sub { diag $t->tx->res->dom->at('title')->text });
527
528 patch_ok
529 $t = $t->patch_ok('http://example.com/foo');
530 $t = $t->patch_ok('/foo');
531 $t = $t->patch_ok('/foo' => {Accept => '*/*'} => 'Content!');
532 $t = $t->patch_ok('/foo' => {Accept => '*/*'} => form => {a => 'b'});
533 $t = $t->patch_ok('/foo' => {Accept => '*/*'} => json => {a => 'b'});
534
535 Perform a "PATCH" request and check for transport errors, takes the
536 same arguments as "patch" in Mojo::UserAgent, except for the callback.
537
538 post_ok
539 $t = $t->post_ok('http://example.com/foo');
540 $t = $t->post_ok('/foo');
541 $t = $t->post_ok('/foo' => {Accept => '*/*'} => 'Content!');
542 $t = $t->post_ok('/foo' => {Accept => '*/*'} => form => {a => 'b'});
543 $t = $t->post_ok('/foo' => {Accept => '*/*'} => json => {a => 'b'});
544
545 Perform a "POST" request and check for transport errors, takes the same
546 arguments as "post" in Mojo::UserAgent, except for the callback.
547
548 # Test file upload
549 my $upload = {foo => {content => 'bar', filename => 'baz.txt'}};
550 $t->post_ok('/upload' => form => $upload)->status_is(200);
551
552 # Test JSON API
553 $t->post_ok('/hello.json' => json => {hello => 'world'})
554 ->status_is(200)
555 ->json_is({bye => 'world'});
556
557 put_ok
558 $t = $t->put_ok('http://example.com/foo');
559 $t = $t->put_ok('/foo');
560 $t = $t->put_ok('/foo' => {Accept => '*/*'} => 'Content!');
561 $t = $t->put_ok('/foo' => {Accept => '*/*'} => form => {a => 'b'});
562 $t = $t->put_ok('/foo' => {Accept => '*/*'} => json => {a => 'b'});
563
564 Perform a "PUT" request and check for transport errors, takes the same
565 arguments as "put" in Mojo::UserAgent, except for the callback.
566
567 request_ok
568 $t = $t->request_ok(Mojo::Transaction::HTTP->new);
569
570 Perform request and check for transport errors.
571
572 # Request with custom method
573 my $tx = $t->ua->build_tx(FOO => '/test.json' => json => {foo => 1});
574 $t->request_ok($tx)->status_is(200)->json_is({success => 1});
575
576 # Request with custom cookie
577 my $tx = $t->ua->build_tx(GET => '/account');
578 $tx->req->cookies({name => 'user', value => 'sri'});
579 $t->request_ok($tx)->status_is(200)->text_is('head > title' => 'Hello sri');
580
581 # Custom WebSocket handshake
582 my $tx = $t->ua->build_websocket_tx('/foo');
583 $tx->req->headers->remove('User-Agent');
584 $t->request_ok($tx)->message_ok->message_is('bar')->finish_ok;
585
586 reset_session
587 $t = $t->reset_session;
588
589 Reset user agent session.
590
591 send_ok
592 $t = $t->send_ok({binary => $bytes});
593 $t = $t->send_ok({text => $bytes});
594 $t = $t->send_ok({json => {test => [1, 2, 3]}});
595 $t = $t->send_ok([$fin, $rsv1, $rsv2, $rsv3, $op, $payload]);
596 $t = $t->send_ok($chars);
597 $t = $t->send_ok($chars, 'sent successfully');
598
599 Send message or frame via WebSocket.
600
601 # Send JSON object as "Text" message
602 $t->websocket_ok('/echo.json')
603 ->send_ok({json => {test => 'I ♥ Mojolicious!'}})
604 ->message_ok
605 ->json_message_is('/test' => 'I ♥ Mojolicious!')
606 ->finish_ok;
607
608 status_is
609 $t = $t->status_is(200);
610 $t = $t->status_is(200, 'right status');
611
612 Check response status for exact match.
613
614 status_isnt
615 $t = $t->status_isnt(200);
616 $t = $t->status_isnt(200, 'different status');
617
618 Opposite of "status_is".
619
620 test
621 $t = $t->test('is', 'first value', 'second value', 'right value');
622
623 Call Test::More functions through "handler", used to implement
624 Test::Mojo roles. The result will be stored in "success".
625
626 text_is
627 $t = $t->text_is('div.foo[x=y]' => 'Hello!');
628 $t = $t->text_is('html head title' => 'Hello!', 'right title');
629
630 Checks text content of the CSS selectors first matching HTML/XML
631 element for exact match with "at" in Mojo::DOM.
632
633 text_isnt
634 $t = $t->text_isnt('div.foo[x=y]' => 'Hello!');
635 $t = $t->text_isnt('html head title' => 'Hello!', 'different title');
636
637 Opposite of "text_is".
638
639 text_like
640 $t = $t->text_like('div.foo[x=y]' => qr/Hello/);
641 $t = $t->text_like('html head title' => qr/Hello/, 'right title');
642
643 Checks text content of the CSS selectors first matching HTML/XML
644 element for similar match with "at" in Mojo::DOM.
645
646 text_unlike
647 $t = $t->text_unlike('div.foo[x=y]' => qr/Hello/);
648 $t = $t->text_unlike('html head title' => qr/Hello/, 'different title');
649
650 Opposite of "text_like".
651
652 websocket_ok
653 $t = $t->websocket_ok('http://example.com/echo');
654 $t = $t->websocket_ok('/echo');
655 $t = $t->websocket_ok('/echo' => {DNT => 1} => ['v1.proto']);
656
657 Open a WebSocket connection with transparent handshake, takes the same
658 arguments as "websocket" in Mojo::UserAgent, except for the callback.
659
660 # WebSocket with permessage-deflate compression
661 $t->websocket_ok('/' => {'Sec-WebSocket-Extensions' => 'permessage-deflate'})
662 ->send_ok('y' x 50000)
663 ->message_ok
664 ->message_is('z' x 50000)
665 ->finish_ok;
666
668 Mojolicious, Mojolicious::Guides, <https://mojolicious.org>.
669
670
671
672perl v5.32.0 2020-07-28 Test::Mojo(3)