I'm trying to follow along with the book Web Development with Node and Express: Leveraging the Javascript Stack and I'm at the point where I have to do cross-page testing. We have a page tours/hood-river which contains a link to tours/request-group-rate and on that page we have a form with a hidden input with name=referrer that is filled with jQuery.
tours/hood-river.handlebars
<h1>Hood River Tour</h1>
<a class="requestGroupRate" href="/tours/request-group-rate">Request Group Rate.</a>
tours/request-group-rate.handlebars
<h1>Request Group Rate</h1>
<form>
<input type="hidden" name="referrer">
Name: <input type="text" id="fieldName" name="name"><br>
Group size: <input type="text" name="groupSize"><br>
Email: <input type="email" name="email"><br>
<input type="submit" value="Submit">
</form>
<script>
$(document).ready(function(){
$('input[name="referrer"]').val(document.referrer);
});
</script>
The tests (with Mocha and Zombie.js)
describe('Cross-Page Tests', function(){
before(function(){
browser = new Browser();
});
it('requesting a group rate quote from the hood river tour page should ' +
'populate the hidden referrer field correctly', function(done){
var referrer = 'http://localhost:3000/tours/hood-river';
browser.visit(referrer, function(){
browser.clickLink('.requestGroupRate', function(){
assert(browser.field('referrer').value === referrer);
done();
});
});
});
(...)
When testing manually, everything works fine but the tests tell me that the field is empty ('') which is confirmed by changing the assert line to:
assert(browser.field('referrer').value === ''); //this passes
I'm guessing when the tests are run, jQuery hasn't run yet? The tests are supposed to pass. What changed or what am I doing wrong?
Aucun commentaire:
Enregistrer un commentaire