Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Test::Mojo::message_* tests. #2153

Merged
merged 1 commit into from
Mar 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
Loading