如何使用zombie来测试<input type =“hidden”/>

时间:2015-04-26 03:13:05

标签: javascript html mocha zombie-process

这是我的观点,我想测试一下。

<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 the URI of the page that links to this page */
     $('input[name="referrer"]').val(document.referrer);
 });
</script>

我写了这样的测试:

var Browser = require('zombie'),
    assert = require('chai').assert;

var browser;

suite('Cross-Page Tests', function() {
    setup(function() {
         browser = new Browser();
    });


    test('requesting a group rate quote from the hood river tour page ' +
         'should populate the 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();
                 });
             });
         });

然后,我运行测试,我发现测试将阻止

browser.assert.input('form input[name="referrer"]', referrer);

(我注释了这一行,测试运行正常)。

我的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"
  }
}

4 个答案:

答案 0 :(得分:2)

你可以试试这个:

assert(browser.resources[0].request.headers._headers[0][1] === referrer);

答案 1 :(得分:0)

您是否在assert中正确地将隐藏元素与referrer变量进行比较?

尝试怎么样:

assert(browser.field('referrer').value === referrer)

答案 2 :(得分:0)

  1. Zombile V3.1:可能不错,但是最新的版本很糟糕。

  2. Zombile主版本有一个错误,也已经解决了,但它还没有合并到主版本。所以,我们正在等待。

  3. 以下是错误:link

答案 3 :(得分:0)

你可以试试这个

browser.assert.element("form input[name=referrer]", referrer);