question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unit tests with Decorators

See original GitHub issue

Hello,

I’m using sesssionStorage decorator inside a service which I want to test.

Because i’m using jest for testing, I don’t have access to SessionStorage. Can I mock the sessionStorage to use InMemoryStorage instead?

I tried to inspire myself with your tests, but nothing worked ( I always have ReferenceError: Storage is not defined)

Thanks for your help

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
Darkeincommented, Nov 7, 2018

Wow, well played, it’s working !

Thanks a lot 😃

PS: I’m using typescript 3.1.3.

0reactions
PillowPillowcommented, Nov 7, 2018

I deployed a new version 3.0.0-beta.12 removing the typescript’s Storage interface usage. Can you remove the LOCAL_STORAGE & SESSION_STORAGE overriding from your test file and tell me if it works?

Hum, I can’t mock LOCAL_STORAGE because it’s injected in the import.

The providers defined in the current module always have the priority over the library ones.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Testing Python decorators - Medium
Testing decorators is tiny bit different. You need to leave decorated function out of the equation and instead verify whether decorator does ...
Read more >
django - Testing Python Decorators? - Stack Overflow
I'm writing some unit tests for a Django project, and I was wondering if its possible (or necessary?) to test some of the...
Read more >
How To Test Python Decorators? How To Bypass A Decorator?
Python decorators can be easily tested by integration tests, but it is good practice to create some unit tests for them as well....
Read more >
unittest — Unit testing framework — Python 3.11.1 ...
Skipping a test is simply a matter of using the skip() decorator or one of its conditional variants, calling TestCase.skipTest() within a setUp()...
Read more >
Things to remember about decorators - James Cooke
When unit testing decorators, one strategy can be to manually call the decorator on a mocked object and inspect how it interacts with...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found