Skip to content

Commit

Permalink
test the description too
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Apr 6, 2015
1 parent b3cfcf0 commit 1f604b6
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 9 deletions.
3 changes: 2 additions & 1 deletion Changes
@@ -1,5 +1,6 @@

6.06 2015-04-05
6.06 2015-04-06
- Added element_count_is method to Test::Mojo. (Zoffix)
- Added "chat.pl" to example scripts.
- Improved Mojo::DOM::CSS to handle attribute selectors with single quotes
correctly.
Expand Down
2 changes: 2 additions & 0 deletions lib/Mojolicious.pm
Expand Up @@ -1019,6 +1019,8 @@ Yuki Kimoto
Zak B. Elep
Zoffix Znet
=back
=head1 COPYRIGHT AND LICENSE
Expand Down
14 changes: 7 additions & 7 deletions lib/Test/Mojo.pm
Expand Up @@ -84,10 +84,10 @@ sub content_type_unlike {
sub delete_ok { shift->_build_ok(DELETE => @_) }

sub element_count_is {
my ($self, $selector, $wanted_count, $desc) = @_;
my ($self, $selector, $count, $desc) = @_;
$desc ||= encode 'UTF-8', qq{element count for selector "$selector"};
my $count = $self->tx->res->dom->find($selector)->size;
return $self->_test('is', $count, $wanted_count, $desc);
my $size = $self->tx->res->dom->find($selector)->size;
return $self->_test('is', $size, $count, $desc);
}

sub element_exists {
Expand Down Expand Up @@ -627,11 +627,11 @@ arguments as L<Mojo::UserAgent/"delete">, except for the callback.
=head2 element_count_is
$t = $t->element_count_is('.product', 6, 'we have 6 elements');
$t = $t->element_count_is('div.foo[x=y]', 5);
$t = $t->element_count_is('html body div', 30, 'thirty elements');
Check the count of elements specified by the selector. Second argument
is the number of elements you expect to find. Third argument is optional,
and specifies the description of the test.
Checks the number of HTML/XML elements matched by the CSS selector with
L<Mojo::DOM/"find">.
=head2 element_exists
Expand Down
3 changes: 2 additions & 1 deletion t/mojolicious/validation_lite_app.t
Expand Up @@ -192,7 +192,8 @@ $t->post_ok('/' => form => {foo => 'no'})->status_is(200)
->element_exists_not('label.custom.field-with-error[for="baz"]')
->element_exists_not('select.field-with-error')
->element_exists_not('input.field-with-error[type="password"]')
->element_count_is('.field-with-error', 2);
->element_count_is('.field-with-error', 2)
->element_count_is('.field-with-error', 2, 'with description');

# Missing CSRF token
$t->get_ok('/forgery' => form => {foo => 'bar'})->status_is(200)
Expand Down

0 comments on commit 1f604b6

Please sign in to comment.