Test::Mojo::Role::Debug - Test::Mojo role to make debugging test failures easier


    use Test::More;
    use Test::Mojo::WithRoles 'Debug';
    my $t = Test::Mojo::WithRoles->new('MyApp');

        ->d         # Does nothing, since test succeeded
        ->d         # Dump entire DOM on fail
        ->d('#foo') # Dump a specific element on fail
        ->da        # Always dump
        ->da('#foo') # Always dump a specific element
        ->da('', 'file.html') # Always dump to a file



When you chain up a bunch of tests and they fail, you really want an easy way to dump up your markup at a specific point in that chain and see what's what. This module comes to the rescue.


You have all the methods provided by Test::Mojo, plus these:


    # On test failure:
    $t->d;         # print entire DOM
    $t->d('#foo'); # print a specific element
    $t->d('', 'file.html');     # dump entire DOM into a file
    $t->d('#foo', 'file.html'); # dump specific element into a file

Returns its invocant. On failure of previous tests (see "success" in Test::Mojo), dumps the DOM of the current page to the screen. Takes an optional selector to be passed to "at" in Mojo::DOM, in which case, only the markup of that element will be dumped.

A filename can be provided as the second argument to put the contents into the file instead. To dump entire DOM, use undef or empty string as the first argument.

NOTE: the plugin detects Mojolicious's error page and will dump only the error text from that page, instead of the entire DOM.


    $t->da('', 'file.html');
    $t->da('#foo', 'file.html');

Same as "d", except it always dumps, regardless of whether the previous test failed or not.


Test::Mojo ("or" in Test::Mojo in particular), Mojo::DOM



To report bugs or request features, please use

If you can't access GitHub, you can email your request to bug-test-mojo-role-debug at




You can use and distribute this module under the same terms as Perl itself. See the LICENSE file included in this distribution for complete details.