iWillGetBetter iWillGetBetter - 1 year ago 56
AngularJS Question

What is the purpose of AngularJS it() and describe() functions?

I have some projects in Javascript/JQuery but AngularJS is a whole new concept to me.

In the docs I have seen the following functions appear alot of time.

describe('PhoneListCtrl', function(){

it('should create "phones" model with 3 phones', function() {
var scope = {},
ctrl = new PhoneListCtrl(scope);



legitimate functions? From the tutorial docs I understand that they are for testing and mock up, but it is still unclear to me how I should run these functions, and if they are merely used as 'foo' and 'bar'.

Answer Source

describe is used to scope tests and it is used to declare them. When the test fails, in your case, you would see a message along the lines of

'should create "phones" model with 3 phones' FAILED!

Followed by some failing assertions. The string provided to it gives context to the assertions.

describe can be used to scope a number of tests to a single topic. Including before and after functions. This is common in lots of testing libraries, not just in javascript. Mocha, Jasmine, but also rspec (from Ruby) use a similar approach.