gpt4 book ai didi

javascript - 清除每个测试的 cookie 不起作用。使用 Karma + Qunit(使用巴甫洛夫)+ Ember。在 PhantomJS/Chrome 中运行

转载 作者:行者123 更新时间:2023-11-28 08:28:56 25 4
gpt4 key购买 nike

我需要在每次测试之前清除登录 cookie,因为之前的测试可能已经存储了该 cookie。这就是我现在所拥有的,但它似乎没有摆脱 cookie/凭证,因为在所述删除后,对客户端的请求仍然达到 200。任何帮助将不胜感激。

 var clearCookies = function() {
var cookiesToDelete = ["cookie1", "cookie2"]
cookiesToDelete.forEach(function(cookie) {
document.cookie = cookie + "=;expires=Thu, 01 Jan 1970 00:00:00 GMT; domain=.domain.com";
})

测试:

describe("CRITERIA 1:", function () {
before(function () {
clearCookies() // Clearing cookies prior to test
App.reset()
visit('/')
})
it(function() {
//asserts in here seem to still use cookie!
})
})

在断言语句中调用 Ajax,在“cookie 删除”后仍然得到 200

$.ajax({
url: clientUrl,
dataType: "json",
xhrFields: {
withCredentials: true
},
success: function() {},
error: function() {}
})

最佳答案

我最终所做的解决方法是调用注销 API,而不是清除 cookie。

describe("CRITERIA 1:", function () {
before(function () {
logout() // logout instead of clearing cookies
App.reset()
visit('/')
})
it(function() {
//asserts in here seem to still use cookie!
})
})

关于javascript - 清除每个测试的 cookie 不起作用。使用 Karma + Qunit(使用巴甫洛夫)+ Ember。在 PhantomJS/Chrome 中运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22074789/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com