File: signatures_lite_app.t

package info (click to toggle)
libmojolicious-perl 8.12%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 3,720 kB
  • sloc: perl: 12,099; makefile: 14
file content (35 lines) | stat: -rw-r--r-- 729 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
use Mojo::Base -strict;

BEGIN { $ENV{MOJO_REACTOR} = 'Mojo::Reactor::Poll' }

use Test::Mojo;
use Test::More;

BEGIN { plan skip_all => 'Perl 5.20+ required for this test!' if $] < 5.020 }

use Mojolicious::Lite -signatures;

helper send_json => sub ($c, $hash) { $c->send({json => $hash}) };

get '/' => sub ($c) {
  $c->render(text => 'works!');
};

websocket '/json' => sub ($c) {
  $c->on(
    json => sub ($c, $hash) {
      $c->send_json($hash);
    }
  );
};

my $t = Test::Mojo->new;

# Plain action
$t->get_ok('/')->status_is(200)->content_is('works!');

# WebSocket
$t->websocket_ok('/json')->send_ok({json => {snowman => '☃'}})
  ->message_ok->json_message_is('' => {snowman => '☃'})->finish_ok;

done_testing();