https://github.com/preaction/test-mojo-role-testdeep
Add Test::Deep methods to Test::Mojo
https://github.com/preaction/test-mojo-role-testdeep
Last synced: 11 months ago
JSON representation
Add Test::Deep methods to Test::Mojo
- Host: GitHub
- URL: https://github.com/preaction/test-mojo-role-testdeep
- Owner: preaction
- License: other
- Created: 2015-08-09T22:52:59.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2016-11-12T04:04:27.000Z (over 9 years ago)
- Last Synced: 2025-04-09T20:43:15.366Z (about 1 year ago)
- Language: Perl
- Size: 32.2 KB
- Stars: 1
- Watchers: 1
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README
- Changelog: CHANGES
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
=head1 SYNOPSIS
use Test::Mojo::WithRoles 'TestDeep';
use Test::Deep; # Get Test::Deep comparison functions
my $t = Test::Mojo::WithRoles->new( 'MyApp' );
# Test JSON responses with Test::Deep
$t->get_ok( '/data.json' )
->json_deeply(
superhashof( { foo => 'bar' } ),
'has at least a foo key with "bar" value',
);
# Test HTML with Test::Deep
$t->get_ok( '/index.html' )
->text_deeply(
'nav a',
[qw( Home Blog Projects About Contact )],
'nav link text matches site section titles',
)
->attr_deeply(
'nav a',
href => [qw( / /blog /projects /about /contact )],
'nav link href matches site section URLs',
);
=head1 DESCRIPTION
This module adds some L functionality to L.
C allows for extremely-customizable testing of data
structures. This module adds some helper methods to C (using
L) to test your web app's responses using
C.
=method json_deeply
$t->json_deeply( $expect, $desc )
$t->json_deeply( $ptr, $expect, $desc )
Test that the current response (parsed as a JSON object) matches the given
tests. C<$expect> is a data structure containing L to run. C<$desc> is an
optional description of the test.
If given, C<$ptr> is a JSON pointer string to pick out a single part of the
data structure. This is more convenient than using Test::Deep's comparison
routines to do the same thing. See L.
Corresponds to L.
=head2 text_deeply
$t->text_deeply( $selector => $expect, $desc );
Test the text of the elements matched by the given C<$selector> against
the given test. C<$expect> is a data structure containing L to run. C<$desc> is
an optional description of the test.
The elements will always be an arrayref, even if only one
element matches.
For example:
# test.html
# test.t
$t->get_ok( 'test.html' )
->text_deeply(
'nav a' => [bag( Home Blog Projects )],
'nav element text is correct',
);
This is equivalent to:
$t->get_ok( 'test.html' );
my $dom = $t->tx->res->dom;
cmp_deeply
[ $dom->find( 'nav a' )->map( 'text' )->each ],
[ bag( Home Blog Projects ) ],
'nav element text is correct';
=head2 attr_deeply
$t->attr_deeply( $selector, $attr => $expect, ..., $desc );
Test the given attributes of the elements matched by the given selector
against the given test. C<$expect> is a data structure containing
L to
run. C<$desc> is an optional description of the test.
The element attributes will always be an arrayref, even if only one
element matches.
For example:
# test.html
...
# test.t
$t->get_ok( 'test.html' )
->attr_deeply(
'form',
action => [qw( /search )],
method => [re( qr( get )i )],
'form element is correct',
);
This is equivalent to:
$t->get_ok( 'test.html' );
my $dom = $t->tx->res->dom;
cmp_deeply
[ $dom->find( 'form' )->map( attr => 'action' )->each ],
[ qw( /search ) ],
'form element action is correct',
;
cmp_deeply
[ $dom->find( 'form' )->map( attr => 'method' )->each ],
[ re( qr( get )i ) ],
'form element method is correct',
;
=head1 SEE ALSO
=over 4
=item L
=item L
=item L
=back