Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enabling local storage in unit tests via the getStorageManager() #9348

Closed
antosarho opened this issue Dec 19, 2022 · 3 comments · Fixed by #9350
Closed

Enabling local storage in unit tests via the getStorageManager() #9348

antosarho opened this issue Dec 19, 2022 · 3 comments · Fixed by #9350
Labels

Comments

@antosarho
Copy link
Contributor

Type of issue

Testing local storage in unit tests does not appear to be possible.

Description

I want to test that our use of getStorageManager() with gvlid and bidderCode specified is working correctly. Nevertheless, whenever I run my unit test, isValid(cb) within storageManager.js always returns undefined because the callback in validateStorageEnforcement is never executed.

Steps to reproduce

In any unit test, set up the following:

    const storage = getStorageManager({gvlid: 855, bidderCode: 'adnuntius'});
     storage.localStorageIsEnabled(); // always returned undefined

You will then find that the callback in validateStorageEnforcement via isValid(cb) is never executed.

Expected results

There should be a way to enable local storage in unit tests.

Other information

This is what I use to run the tests: gulp test --file ./test/spec/modules/adnuntiusBidAdapter_spec.js

@dgirardi
Copy link
Collaborator

First, I recommend using serve-and-test instead of test during development - it's quite a bit faster (it skips linting and doesn't need to recompile the world on each test run).

To solve your issue, add this at the top of your _spec.js file:

import {hook} from 'src/hook.js';

before(() => {
  hook.ready();
});

@patmmccann
Copy link
Collaborator

Testing local storage in unit tests does not appear to be possible.

Fwiw, it does work when you run all the tests, the problem at hand is that it doesnt work when you only run this subset of the tests.

@antosarho
Copy link
Contributor Author

That does the trick!

Thanks muchly. And thanks muchly for merging the change to master to enable this by default.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Development

Successfully merging a pull request may close this issue.

3 participants