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

Expose dom as an attribute on Test::Mojo #1045

Closed
wants to merge 1 commit into from
Closed

Expose dom as an attribute on Test::Mojo #1045

wants to merge 1 commit into from

Conversation

marcusramberg
Copy link
Member

Summary

Expose dom as an attribute on Test::Mojo to allow testing Mojo::DOM objects without involving a user agent. Also makes some tests in t/mojo/mojo-dom.t a bit simpler to read.

Motivation

This makes it easy to use Test::Mojo to test the contents of HTML/XML strings.

@jberger
Copy link
Member

jberger commented Jan 30, 2017

I've wanted this on the off occasion where there are mixed api return types, like a JSON api for which one of the values is HTML.

@jberger
Copy link
Member

jberger commented Jan 30, 2017

I'm less sure about changing how the t/mojo/dom.t tests test Mojo::DOM (now via Test::Mojo) but the rest I'm mildly 👍 on

@@ -17,7 +17,8 @@ use Mojo::Util qw(decode encode);
use Test::More ();

has [qw(message success tx)];
has ua => sub { Mojo::UserAgent->new->ioloop(Mojo::IOLoop->singleton) };
has ua => sub { Mojo::UserAgent->new->ioloop(Mojo::IOLoop->singleton) };
has dom => sub { shift->tx->res->dom };
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is an attribute really needed here? How much faster is it than a method?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it is intended as a shortcut but rather as an assignable DOM.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, the idea is that you can use Test::Mojo dom methods without doing a request by assigning a Mojo::DOM object, as illustrated by the changes in t/mojo/dom.t

@kraih
Copy link
Member

kraih commented Jan 30, 2017

👎 Really don't like the changes in dom.t. If you want better test coverage for Test::Mojo, then i believe the right way to do it would be a new test file with tests for pass and fail. Not sure how to do it best, but i bet other test modules on CPAN have tests too.

@marcusramberg
Copy link
Member Author

marcusramberg commented Jan 30, 2017 via email

@jberger
Copy link
Member

jberger commented Jan 30, 2017

FYI, once Perl ships a major (minor, sigh) version with Test2 (perl 5.25.1 includes it, so perl 5.26 will), I intend to rewrite the Test::Mojo internals and test them better (with approval of course).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants