简体   繁体   中英

Clearing cookies for each test not working. Using Karma + Qunit (using Pavlov) + Ember. Running in PhantomJS/Chrome

I need to clear a login cookie before each test as previous tests might have stored the cookie. This is what I have right now, but it does not seem to get rid of cookies/credentials as requests for clients still get 200 after said deletion. Any help would be much appreciated.

 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";
        })

Test:

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 called within assert statement that still gets a 200 after "cookie deletion"

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

Work around I ended up doing was calling a logout API instead of clearing the cookies.

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!          
    })
})

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM