Skip to content

Instantly share code, notes, and snippets.

@pushkar100
Created July 6, 2022 15:13
Show Gist options
  • Save pushkar100/2dd1176c96d4dc0ab653cf2f37d6a5b4 to your computer and use it in GitHub Desktop.
Save pushkar100/2dd1176c96d4dc0ab653cf2f37d6a5b4 to your computer and use it in GitHub Desktop.
/* testing/src/__tests__/helpers/index.test.js */
import { /* ... */ , setTraysForId, getTraysForId } from '../../helpers';
describe('Trays', () => {
beforeEach(() => {
window.localStorage.clear();
});
test('are stored locally on setting them via the id', () => {
const id = 123;
const trays = ['movies', 'cartoons', 'true crime'];
const stringifiedTrays = JSON.stringify(trays);
setTraysForId(id, trays);
expect(window.localStorage.getItem(`${id}`)).toEqual(stringifiedTrays);
});
test('are fetched locally on searching for them via the id', () => {
const id = 123;
const trays = ['movies', 'cartoons', 'true crime'];
const stringifiedTrays = JSON.stringify(trays);
setTraysForId(id, trays);
const actualTrays = getTraysForId(id);
expect(actualTrays).toEqual(trays);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment