Created
November 17, 2012 18:50
-
-
Save TristinDavis/4098770 to your computer and use it in GitHub Desktop.
Example of Test::Mojo used to unit test.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"> | |
<html> | |
<head> | |
<title>Hello</title> | |
</head> | |
<body> | |
<ul> | |
<li> | |
<a href="Goodbye.html">Goodbye page</a> | |
</li> | |
<li> | |
<a href="Hello.html" target="_blank">Hello page</a> | |
</li> | |
</ul> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use strict; | |
use warnings; | |
use Test::More tests => 6; | |
use Test::Mojo; | |
my $url = 'http://localhost/~rhaen/index.html'; | |
my $t = Test::Mojo->new; | |
# Easy - get the title string | |
$t->get_ok($url) | |
->text_is('html head title' | |
=> 'Hello', 'correct title'); | |
# Still easy - get the <a> test | |
$t->get_ok($url) | |
->text_is('a[target]' | |
=> 'Hello page', 'correct text for a tag'); | |
# Advanced - checking for attribute value | |
$t->get_ok($url) | |
->element_exists('a[href=Hello.html]', 'Yep, attribute value ok'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment