File: signatures_lite_app.t

package info (click to toggle)
libmojolicious-perl 9.39%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 4,324 kB
  • sloc: perl: 10,319; makefile: 31; javascript: 1
file content (37 lines) | stat: -rw-r--r-- 775 bytes parent folder | download | duplicates (3)
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
36
37
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;

subtest 'Plain action' => sub {
  $t->get_ok('/')->status_is(200)->content_is('works!');
};

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

done_testing();