Protractor - empty local storage

前端 未结 5 767
臣服心动
臣服心动 2020-12-03 13:30

I\'m using Protractor (with Jasmine) to test my AngulaJs application.

As result of some of my action I get some data saved in the localStorage. Now I need to test ot

5条回答
  •  Happy的楠姐
    2020-12-03 14:02

    I haven't found a cool way to do that, but if I run my statement

     browser.executeScript("localStorage.removeItem('config');")
    

    within a it('description') statement it works. Example:

    it('should compile and save base config for billing',function(){
        browser.executeScript("localStorage.removeItem('config');")
    
        //my test
    });
    

    This remove the item named config, and so my test works, but while searching and talking about this issue the main response I got is:

    "localStorage is not you product, so you don't need (read: you must not) test it. The right way is to mock it and inject it contents when they are needed"

    I'm still looking into this to understrand how, meanwhile I think that a not philosophically perfect test is still better than nothing so..

    Hope this helps...

提交回复
热议问题