4

我正在尝试为实习生功能测试设置 cookie,但页面上似乎没有 cookie 数据。这是设置:

registerSuite(function() {
    'test': function() {
        return this.remote 
           .get(require.toUrl("index.html")
           .setFindTimeout(5000)
           .setCookie({name: "foo", value: "bar"})
           .then(function() {
              //... test here ...
           });
    }
});

访问 index.html 中的 document.cookie 时,没有数据。关于我做错了什么的任何提示?

更新

我还没有解决问题,但发现您需要在 get() 之前调用 setCookie()。我解决这个问题的方法是在 noop URL 上调用 get(),然后调用 setCookie()

return this.remote 
       .get('/')
       .setCookie({name: "foo", value: "bar"})
       .get(require.toUrl("index.html")
       .setFindTimeout(5000)
       .setCookie({name: "foo", value: "bar"})
       .then(function() {
          //... test here ...
       });
4

1 回答 1

-1

您的示例代码中似乎没有包含任何setup、或. 我建议在评估您希望它创建的 cookie 之前确保该功能完全正常工作。teardown/afterbeforeEachafterEach

我对 Intern.JS 不是很熟悉,但我相信从我阅读的内容来看,测试只是一个测试,一旦完成,它们就会从测试中删除信息,以便可以执行下一个测试。因此,当 cookie 存在并且测试完成时它被销毁时,您可能会丢失。

于 2015-07-30T19:47:09.617 回答