dimanche 4 décembre 2016

Check if function returns sessionStorage with jest

I am trying to write a jest test for following function, that sets sessionStorage entry:

/**
 * @desc create authenticated user session
 * @param  {String} [email='']
 * @param  {Date} [expires=Date.now()]
 * @param  {String} [hash='']
 * @param  {Array} users
 * @return {Session}
 */
export const setSession = (
  email = '',
  expires = Date.now(),
  hash = '',
  users: []) => {
  const session = {
    email,
    expires,
    hash,
    users
  };
  sessionStorage.setItem('MY_SESSION', JSON.stringify(session));
};

I am confused to where to start i.e. I get jest error saying that session storage is not defined in a simple test like this:

it('takes in session parameters and returns sessionStorage', () => {
  console.log(setSession('test@me.io', Date.now(), 'ha_sh', []));
});

Aucun commentaire:

Enregistrer un commentaire