@@ -5,6 +5,10 @@ use Test::Mojo;
5
5
use Mojolicious::Lite;
6
6
7
7
any ' /' => {text => ' Hello Test!' };
8
+ websocket ' /websocket' , => sub {
9
+ my ($c ) = @_ ;
10
+ $c -> send ({text => ' testing message' });
11
+ };
8
12
9
13
my $t = Test::Mojo-> new;
10
14
@@ -217,4 +221,45 @@ subtest 'header_unlike' => sub {
217
221
is_deeply \@args , [' unlike' , ' text/html;charset=UTF-8' , qr / image\/ png/ , ' some description' ], ' right result' ;
218
222
};
219
223
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
+
220
265
done_testing();
0 commit comments