Company logo
  • Jobs
  • Bootcamp
  • About Us
  • For professionals
    • Home
    • Jobs
    • Courses and challenges
    • Questions
    • Teachers
    • Bootcamp
  • For business
    • Home
    • Our process
    • Plans
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Calculator

0

95
Views
Is there a way to test whether or not something is added to localStorage?

I am currently testing a login function where the user_id of the logged in user should be added to localStorage. However, i am unable to test this because of an uncaught reference error: "localStorage is not defined" Could somebody help me figure this out? Have tried 'mocking' localStorage without succes. Using mocha and chai for testing.

// Test if user_id is added to localstorage
it('should add user_id to localstorage', (done) => {
    chai.request(app)
        .post('/login')
        .send({
            username: 'admin',
            password: '1234'
        })
        .end((err, res) => {
            expect(localStorage.getItem('user_id')).to.equal('1');
            done();
        }
        );
}
);
7 months ago ยท Juan Pablo Isaza
Answer question
Find remote jobs