Update a global variable with in an it call

23 views
Skip to first unread message

Devan Shah

unread,
May 17, 2016, 4:23:37 PM5/17/16
to Jasmine
Hello

Is it at all possible to use it clause to actually populate an array and then use this variable again.


describe("Rule Unit Tests", function () {
    var example;

    it("Build Global UnitTest Map", function () {
        example = "Hello"; ---> Set to Hello
    });
    
    console.log(example); ---> Want to access the changes version here
   
});

Regards

Gregg Van Hove

unread,
Aug 16, 2016, 2:44:42 PM8/16/16
to jasmi...@googlegroups.com
An `it` can modify global state, but it won't quite work how you have your example set up. The `function` you pass to the `it` will not be executed until Jasmine starts to run all of the specs in your suite. This means that the `console.log` will have already run (during loading of the suite), by the time the `it` has any chance to update the `example` variable.

Hope this helps. Thanks for using Jasmine!

-Gregg

--
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+unsubscribe@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.

Reply all
Reply to author
Forward
0 new messages