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