I want to check the status of ls after the action, but it is returning undefined. How can I mock the storage? Is toHaveBeenCalledWith the only way, or is there another way to check the functions?
<code>describe('setTheme', () => {
it('should set theme to light', () => {
// Dispatch Action
store.dispatch(setTheme('light'));
// Mocked Expected
expect(store.getState().misc.theme).toEqual('light');
// Check localStorage
expect(localStorage.setItem).toHaveBeenCalledWith('theme', JSON.stringify('light'));
// Check if the theme is correctly set in localStorage
const storedThemeItem = localStorage.getItem('theme');
if (storedThemeItem !== null && storedThemeItem !== undefined) {
const storedTheme = JSON.parse(storedThemeItem);
expect(storedTheme).toEqual('light');
} else {
throw new Error('Theme not found in localStorage');
}
});
}</code>
<code>describe('setTheme', () => {
it('should set theme to light', () => {
// Dispatch Action
store.dispatch(setTheme('light'));
// Mocked Expected
expect(store.getState().misc.theme).toEqual('light');
// Check localStorage
expect(localStorage.setItem).toHaveBeenCalledWith('theme', JSON.stringify('light'));
// Check if the theme is correctly set in localStorage
const storedThemeItem = localStorage.getItem('theme');
if (storedThemeItem !== null && storedThemeItem !== undefined) {
const storedTheme = JSON.parse(storedThemeItem);
expect(storedTheme).toEqual('light');
} else {
throw new Error('Theme not found in localStorage');
}
});
}</code>
describe('setTheme', () => {
it('should set theme to light', () => {
// Dispatch Action
store.dispatch(setTheme('light'));
// Mocked Expected
expect(store.getState().misc.theme).toEqual('light');
// Check localStorage
expect(localStorage.setItem).toHaveBeenCalledWith('theme', JSON.stringify('light'));
// Check if the theme is correctly set in localStorage
const storedThemeItem = localStorage.getItem('theme');
if (storedThemeItem !== null && storedThemeItem !== undefined) {
const storedTheme = JSON.parse(storedThemeItem);
expect(storedTheme).toEqual('light');
} else {
throw new Error('Theme not found in localStorage');
}
});
}