Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 6ac9f2c

Browse files
committedFeb 11, 2024
Adding Test::Mojo::message_* tests.
1 parent 37a4c39 commit 6ac9f2c

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed
 

‎t/test/mojo.t

+45
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ use Test::Mojo;
55
use Mojolicious::Lite;
66

77
any '/' => {text => 'Hello Test!'};
8+
websocket '/websocket', => sub {
9+
my ($c) = @_;
10+
$c->send({text => 'testing message'});
11+
};
812

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

@@ -217,4 +221,45 @@ subtest 'header_unlike' => sub {
217221
is_deeply \@args, ['unlike', 'text/html;charset=UTF-8', qr/image\/png/, 'some description'], 'right result';
218222
};
219223

224+
subtest 'message_is' => sub {
225+
$t->websocket_ok('/websocket')->message_ok->message_is('testing message');
226+
is_deeply \@args, ['is', ('testing message') x 2, 'exact match for message'], 'message_is succeded.';
227+
$t->websocket_ok('/websocket')->message_ok->message_is('testing message', 'some description');
228+
is_deeply \@args, ['is', ('testing message') x 2, 'some description'], 'message_is prints correct test message.';
229+
$t->websocket_ok('/websocket')->message_ok->message_is('incorrect testing message');
230+
is_deeply \@args, ['is', 'testing message', 'incorrect testing message', 'exact match for message'], 'message_is fails.';
231+
};
232+
233+
subtest 'message_isnt' => sub {
234+
$t->websocket_ok('/websocket')->message_ok->message_isnt('testing message');
235+
is_deeply \@args, ['isnt', ('testing message') x 2, 'no match for message'], 'message_isnt fails.';
236+
$t->websocket_ok('/websocket')->message_ok->message_isnt('testing message', 'some description');
237+
is_deeply \@args, ['isnt', ('testing message') x 2, 'some description'], 'message_isnt prints correct test message.';
238+
$t->websocket_ok('/websocket')->message_ok->message_isnt('incorrect testing message');
239+
is_deeply \@args, ['isnt', 'testing message', 'incorrect testing message', 'no match for message'], 'message_isnt succeded.';
240+
};
241+
242+
subtest 'message_like' => sub {
243+
$t->websocket_ok('/websocket')->message_ok->message_like(qr/^test/);
244+
is_deeply \@args, ['like', 'testing message', qr/^test/, 'message is similar'], 'message_like succeded.';
245+
$t->websocket_ok('/websocket')->message_ok->message_like(qr/^test/, 'some description');
246+
is_deeply \@args, ['like', 'testing message', qr/^test/, 'some description'], 'message_like prints correct test message.';
247+
};
248+
249+
subtest 'message_ok' => sub {
250+
$t->websocket_ok('/websocket')->message_ok;
251+
is_deeply \@args, ['ok', !!1, 'message received'], 'message_ok succeded.';
252+
$t->websocket_ok('/websocket')->message_ok('some description');
253+
is_deeply \@args, ['ok', !!1, 'some description'], 'message_ok prints correct test message.';
254+
$t->websocket_ok('/')->message_ok;
255+
is_deeply \@args, ['ok', !!0, 'message received'], 'message_ok failed.';
256+
};
257+
258+
subtest 'message_unlike' => sub {
259+
$t->websocket_ok('/websocket')->message_ok->message_unlike(qr/^test/);
260+
is_deeply \@args, ['unlike', 'testing message', qr/^test/, 'message is not similar'], 'message_unlike failed.';
261+
$t->websocket_ok('/websocket')->message_ok->message_unlike(qr/^test/, 'some description');
262+
is_deeply \@args, ['unlike', 'testing message', qr/^test/, 'some description'], 'message_unlike prints correct test message.';
263+
};
264+
220265
done_testing();

0 commit comments

Comments
 (0)
Please sign in to comment.