Skip to content

Commit

Permalink
Adding Test::Mojo::message_* tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
sergiotarxz committed Feb 11, 2024
1 parent 37a4c39 commit dd49a47
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions t/test/mojo.t
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ use Mojolicious::Lite;

any '/' => {text => 'Hello Test!'};

websocket '/websocket' => sub {
my $c = shift;
$c->send({text => 'testing message'});
};

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

subtest 'Basics' => sub {
Expand Down Expand Up @@ -217,4 +222,45 @@ subtest 'header_unlike' => sub {
is_deeply \@args, ['unlike', 'text/html;charset=UTF-8', qr/image\/png/, 'some description'], 'right result';
};

subtest 'message_is' => sub {
$t->websocket_ok('/websocket')->message_ok->message_is('testing message');
is_deeply \@args, ['is', 'testing message', 'testing message', 'exact match for message'], 'right result';
$t->websocket_ok('/websocket')->message_ok->message_is('testing message', 'some description');
is_deeply \@args, ['is', 'testing message', 'testing message', 'some description'], 'right result';
$t->websocket_ok('/websocket')->message_ok->message_is('incorrect testing message');
is_deeply \@args, ['is', 'testing message', 'incorrect testing message', 'exact match for message'], 'right result';
};

subtest 'message_isnt' => sub {
$t->websocket_ok('/websocket')->message_ok->message_isnt('testing message');
is_deeply \@args, ['isnt', 'testing message', 'testing message', 'no match for message'], 'right result.';
$t->websocket_ok('/websocket')->message_ok->message_isnt('testing message', 'some description');
is_deeply \@args, ['isnt', 'testing message', 'testing message', 'some description'], 'right result';
$t->websocket_ok('/websocket')->message_ok->message_isnt('incorrect testing message');
is_deeply \@args, ['isnt', 'testing message', 'incorrect testing message', 'no match for message'], 'right result';
};

subtest 'message_like' => sub {
$t->websocket_ok('/websocket')->message_ok->message_like(qr/^test/);
is_deeply \@args, ['like', 'testing message', qr/^test/, 'message is similar'], 'right result';
$t->websocket_ok('/websocket')->message_ok->message_like(qr/^test/, 'some description');
is_deeply \@args, ['like', 'testing message', qr/^test/, 'some description'], 'right result';
};

subtest 'message_ok' => sub {
$t->websocket_ok('/websocket')->message_ok;
is_deeply \@args, ['ok', !!1, 'message received'], 'right result';
$t->websocket_ok('/websocket')->message_ok('some description');
is_deeply \@args, ['ok', !!1, 'some description'], 'right result';
$t->websocket_ok('/')->message_ok;
is_deeply \@args, ['ok', !!0, 'message received'], 'right result';
};

subtest 'message_unlike' => sub {
$t->websocket_ok('/websocket')->message_ok->message_unlike(qr/^test/);
is_deeply \@args, ['unlike', 'testing message', qr/^test/, 'message is not similar'], 'right result';
$t->websocket_ok('/websocket')->message_ok->message_unlike(qr/^test/, 'some description');
is_deeply \@args, ['unlike', 'testing message', qr/^test/, 'some description'], 'right result';
};

done_testing();

0 comments on commit dd49a47

Please sign in to comment.