How to get localStorage value into jasmine test

259 views
Skip to first unread message

ajay k

unread,
Dec 13, 2018, 7:23:23 AM12/13/18
to Jasmine
Hi,
I am using angular-loacalStorage. I stored a value in local storage and how can i get that value in my tescasae. I injected local storage service and also in inside files files:[] in karma.conf. Once i run and scope variable that has localstorage value it show undefined. And also can I get var test = "Welcome" the value of test in my test case? Can any one please help on those two. Thanks in advance

Gregg Van Hove

unread,
Dec 13, 2018, 8:42:19 PM12/13/18
to jasmi...@googlegroups.com
I don't know much about Angular-localStorage or the karma config to make it work but, if I understand correctly, I think I can help with your second question.

It sounds like you want to use the value of some variable in the description of a test. Assuming that is correct, you should be able to use basic string concatenation (or any other mechanism) like so:

it('shows the string: ' + test, function() {});

To create a test based off of the value of a variable at suite declaration time. Note that setting this in a `beforeEach` will not get you what you want.

Hope this helps. Thanks for using Jasmine!

- Gregg

On Thu, Dec 13, 2018 at 4:23 AM ajay k <konda.aj...@gmail.com> wrote:
Hi,
I am using angular-loacalStorage. I stored a value in local storage and how can i get that value in my tescasae. I injected local storage service and also in inside files files:[] in karma.conf. Once i run and scope variable that has localstorage value it show undefined. And also can I get var test = "Welcome" the value of test in my test case? Can any one please help on those two. Thanks in advance

--
You received this message because you are subscribed to the Google Groups "Jasmine" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jasmine-js+...@googlegroups.com.
To post to this group, send email to jasmi...@googlegroups.com.
Visit this group at https://groups.google.com/group/jasmine-js.
For more options, visit https://groups.google.com/d/optout.

ajay k

unread,
Dec 14, 2018, 1:24:25 AM12/14/18
to Jasmine
Hi Gregg,

Thanks for helping. But i need to test variable value that is present in controller like in controller var test = "Welcome", and I need to write a test case for that variable it('teting the variable value', function() {expect(test).toBe("welcome")}). Is it possible to gat variable value from controller I can get with scope variable but i dont want to make that as scope variable. Is it possible to achieve that.

Gregg Van Hove

unread,
Dec 14, 2018, 8:05:07 PM12/14/18
to jasmi...@googlegroups.com
Jasmine really just runs your Javascript code, so anything you can access from another component can be accessed from your tests.

-Gregg

ajay konda

unread,
Dec 14, 2018, 8:06:40 PM12/14/18
to jasmi...@googlegroups.com
Can please tell me how to access it. It will be helpful 
Reply all
Reply to author
Forward
0 new messages