Edit jor package.json and add
"setupFiles": [
"<rootDir>/MYPATH/polyfills.js"
],
Your test file should look like
describe(Component.name, () => {
it('should save to localStorage', () => {
const KEY = 'foo';
const VALUE = 'bar';
localStorage.setItem(KEY, VALUE);
// Or localStorage[KEY] = VALUE;
expect(localStorage.getItem(KEY)).toBe(VALUE);
});
});