DEV Community

Discussion on: Testing Svelte stores and mocking dependencies

Collapse
 
d_ir profile image
Daniel Irvine πŸ³οΈβ€πŸŒˆ

What version of JSDOM are you using? The latest version has an implementation of localStorage ready to go, I think.

You can also use spies but I wouldn’t bother with using a package for it (although that’s what I say about everything to be fair, so ymmv πŸ€·β€β™‚οΈ)

Here’s an example of how I used spies to test local storage in a React codebase (with Jest):

github.com/PacktPublishing/Masteri...

Collapse
 
jeffwscott profile image
Jeff Scott

So now I need to learn Jest or does Jasmine have spies, also I guess I need to find out what spies are lol.

I'm using whatever JSDOM you had in your dependency tree. I copied them out.

Thread Thread
 
d_ir profile image
Daniel Irvine πŸ³οΈβ€πŸŒˆ

Jasmine has spies - jasmine.createSpy

I’ll see if I can port across the local storage tests to Svelte a little later today.