What does the "it" function do in this code?
Solution 1
See the Jasmine testing framework.
The it(...)
function defines a test case (aka a "spec").
describe("A suite", function() {
it("contains spec with an expectation", function() {
expect(true).toBe(true);
});
});
Note that AngularJS E2E Testing...
... uses Jasmine for its test syntax.
Solution 2
So 'it' is referring to when you're testing your application, and only when you're testing. The point of testing is that you can have the test runner automate a bunch of the regular tasks your users would normally do then validate all the responses/events from those tasks work correctly. What your code is saying is that your test 'should check ng-show/ng-hide' and validate that they're working properly. You'll only see 'it' used in test runner like Karma or Jasmine.
Related videos on Youtube
tarrball
Updated on July 09, 2022Comments
-
tarrball almost 2 years
I'm hoping somebody could explain to me what "it" does (is used for) in AngularJS or just plain JavaScript (I'm not sure if it's specific to Angular). This, turns out, is a difficult thing to Google for, being named "it" and all. I've seen it used throughout the AngularJS docs. I'll give you an example from the ngShow page (it's code to hide/show a div containing a thumbs up or thumbs down).
var thumbsUp = element(by.css('span.glyphicon-thumbs-up')); var thumbsDown = element(by.css('span.glyphicon-thumbs-down')); it('should check ng-show / ng-hide', function() { expect(thumbsUp.isDisplayed()).toBeFalsy(); expect(thumbsDown.isDisplayed()).toBeTruthy(); element(by.model('checked')).click(); expect(thumbsUp.isDisplayed()).toBeTruthy(); expect(thumbsDown.isDisplayed()).toBeFalsy(); });