Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does the "it" function do in this code?

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(); }); 
like image 489
tarrball Avatar asked Jun 10 '14 15:06

tarrball


People also ask

What is a function in JavaScript?

A JavaScript function is a block of code designed to perform a particular task. A JavaScript function is executed when "something" invokes it (calls it).

What is a function in HTML?

A function contains some code that will be executed by an event or a call to that function. A function is a set of statements. You can reuse functions within the same script, or in other documents. You define functions at the beginning of a file (in the head section), and call them later in the document.

Does HTML have functions?

html example. This contains two functions called a() and b() , and three variables — x , y , and z — two of which are defined inside the functions, and one in the global scope. It also contains a third function called output() , which takes a single parameter and outputs it in a paragraph on the page.

How do I execute a JavaScript function?

Use the keyword function followed by the name of the function. After the function name, open and close parentheses. After parenthesis, open and close curly braces. Within curly braces, write your lines of code.


1 Answers

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.

like image 106
maerics Avatar answered Oct 23 '22 06:10

maerics