The following snippet of code is from angular's documentation. What is the it()
function here doing (I'm assuming it has some conventional meaning because otherwise no context seems to be given for its meaning)? I don't see any reference to it on angular's site. It's also hard to google due to it's name. The context is with regards to code testing.
it('should say hello', function() { var scopeMock = {}; var cntl = new MyController(scopeMock); // Assert that username is pre-filled expect(scopeMock.username).toEqual('World'); // Assert that we read new username and greet scopeMock.username = 'angular'; scopeMock.sayHello(); expect(scopeMock.greeting).toEqual('Hello angular!'); });
In JavaScript, we have many frameworks dealing with individual concerns, and Jasmine is one of those many. It is a unit testing framework, and it has its documentation already packed up. One of the functions of this framework is the it() function that enables the user/admin to get the total outcome of the code lines.
You call the function by typing its name and putting a value in parentheses. This value is sent to the function's parameter. e.g. We call the function firstFunction(“string as it's shown.”);
A closure is a link between a function and its outer lexical (ie. as-written) environment, such that the identifiers (variables, parameters, function declarations etc) defined within that environment are visible from within the function, regardless of when or from where the function is invoked.
describe(string, function) functions take a title and a function containing one or more specs and are also known as a suite or test suite. it(string, function) functions take a title and a function containing one or more expectations and are also known as specs. expect(actual) functions take a value, called an actual.
The it()
function is defined by the jasmine testing framework, it is not part of angular per se. You'll see it in angular's documentation because they are encouraging you (for good reason) to get in the habit of writing tests for your code, and demonstrating how the code will work in a test.
The it()
function defines a jasmine test. It is so named because its name makes reading tests almost like reading English. The second argument to the it()
function is itself a function, that when executed will probably run some number of expect()
functions. expect()
functions are used to actually test the things you "expect" to be true.
Read more about jasmine testing on the jasmine framework's website: http://jasmine.github.io/
it is related to tests with jasmine framework, you can find more information here: http://jasmine.github.io/
https://docs.angularjs.org/guide/unit-testing
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With