> On 20 October 2014 09:51, Martin Danielson <
martin.d...@quinyx.com> wrote:
>
> Sorry for the late response, been taking care of my sick son and wife.
>
>
> setup and teardown, how do you accomplish this? Is there an example you can show me? In Jasmine we have beforeEach and afterEach, but that would require us to include those mocks in every test. I would rather have these globals being mocked for all tests automatically so that we do not have to write so much boiler code. Right now, I am circumventing the problem by loading the data I need in env-setup.js and putting a condition on localStorage - not very nice at all and rather inflexible as I said before.
>
>
> I tried mocking localStorage using spyOn but for whatever reason it never worked. Whatever I did with localStorage it complained about it not being specified. I think I tested having it both in beforeEach and also in env-setup.js. I think this is specific to Jest, since the code was written for Jasmine and should work there.
>
>
> The best solution in my mind is having these things set up in env-setup.js (or simular) and then being able to be configured individually in tests (if needed).
>
>
> I will give this another go soon, when I am back at work.
>
>
> Thank you for replying and sharing,
> Martin
>
>
>
>
>
>
>
> Martin Danielson
> Front Tech Lead
>
>
> Mobile:
+46 (0)72 222 26 44
>
martin.d...@quinyx.com
>
>
> QUINYX AB
> Vattugatan 17111 52 STOCKHOLM
>
>
>
>
>
>
>
>
>
> On 15 October 2014 16:58, vjeux <
vje...@gmail.com> wrote:
>
> For localStorage tests we usually make a mock of localStorage in setup() and revert the global in teardown(). This way it's mocked like any other dependency.
>
>
> Do you have ideas in how to make it easier to work with?
>
>
>
>
>
>
> On Wednesday, October 15, 2014 12:55:51 AM UTC-7, Martin Danielson wrote:
> I would like to use Jest for all our unit tests in order to keep the number of test frameworks down. Jest is superior to any alternative we've used since the auto-mocking is incredible and outweighs the problem with speed.
>
>
> However, is there a pattern used/recommended for handling globals? Specifically localStorage.
>
>
> I've looked at a few ways recommended by Jasmine but they do not really work as far as I have tested. Right now we are conditioning the existence of localStorage in the code and then we populate anything related to getting information from the localStorage manually before every test. It works but it is not very flexible. I.e. language definitions that are stored in localStorage becomes a bit cumbersome to test (with different languages).
>
>
> So, anyone have any good solutions to share, maybe anyone at the Jest team who have looked into this?
>
>
> Kind regards,
> Martin
>
>
>
>
>
>
> --
>
> You received this message because you are subscribed to the Google Groups "Jest" group.
>
> To unsubscribe from this group and stop receiving emails from it, send an email to
jestjs+un...@googlegroups.com.
>
> To view this discussion on the web visit
https://groups.google.com/d/msgid/jestjs/074463a3-2fe1-4323-bb16-b63d49d55082%40googlegroups.com.
>
>
>
> For more options, visit
https://groups.google.com/d/optout.