javascript - How to use zombie to test <input type="hidden"> -
this view, want test.
<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() { /* document.referrer: returns uri of page links page */ $('input[name="referrer"]').val(document.referrer); }); </script>
i wrote test this:
var browser = require('zombie'), assert = require('chai').assert; var browser; suite('cross-page tests', function() { setup(function() { browser = new browser(); }); test('requesting group rate quote hood river tour page ' + 'should populate referrer field', function(done) { var referrer = 'http://localhost:3000/tours/hood-river'; browser.visit(referrer, function() { browser.clicklink('.requestgrouprate', function() { browser.assert.input('form input[name="referrer"]', referrer); done(); }); }); });
then, run test, found test block @
browser.assert.input('form input[name="referrer"]', referrer);
(i annotate line, , test runs ok).
my package.json:
{ "name": "meadowlark", "version": "1.0.0", "description": "a travel website", "main": "meadowlark.js", "scripts": { "test": "grunt" }, "repository": { "type": "git", "url": "https://github.com/zwb-ict/meadowlark.git" }, "keywords": [ "node" ], "author": "zwb.ict@gmail.com", "license": "mit", "bugs": { "url": "https://github.com/zwb-ict/meadowlark/issues" }, "homepage": "https://github.com/zwb-ict/meadowlark", "dependencies": { "express": "^4.12.3", "express-handlebars": "^2.0.0" }, "devdependencies": { "chai": "^2.2.0", "grunt": "^0.4.5", "grunt-contrib-jshint": "^0.11.2", "grunt-exec": "^0.4.6", "grunt-istanbul": "^0.5.0", "grunt-mocha-test": "^0.12.7", "istanbul": "^0.3.13", "mocha": "^2.2.4", "zombie": "^3.0.0" } }
you can try this:
assert(browser.resources[0].request.headers._headers[0][1] === referrer);
Comments
Post a Comment