Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is the "expect" function used in angular js

In the Angular documentation they write this:

expect(scope.counter).toEqual(0);

and this was written in many places like here.

I just want to know what it does

like image 708
Mirage Avatar asked Nov 07 '12 02:11

Mirage


People also ask

What is Q defer () in AngularJS?

Simply put you can use $q. defer() to create a Promise. A Promise is a function that returns a single value or error in the future. So whenever you have some asynchronous process that should return a value or an error, you can use $q. defer() to create a new Promise.

What is promises in AngularJS?

Promises in AngularJS are provided by the built-in $q service. They provide a way to execute asynchronous functions in series by registering them with a promise object. {info} Promises have made their way into native JavaScript as part of the ES6 specification.

What is describe in AngularJS?

describe defines a test suite, and it defines a "spec" or a test. From the Jasmine documentation: A test suite begins with a call to the global Jasmine function describe with two parameters: a string and a function. The string is a name or title for a spec suite - usually what is under test.


2 Answers

This is Jasmine unit testing framework syntax for unit tests. Angular uses, promotes and encourages unit testing practices.

Testability is taken very seriously in AngularJS and the authors of the framework make sure that code written using AngularJS is easy to test:

  • Built-in dependency injection (DI) system makes it easy to combine an application from smaller, well tested elements
  • Accompanying tooling - Testacular - makes it easy to write and execute tests in practice

AngularJS has also a solution for higher-level, end-to-end testing. E2e tests use a very similar syntax (so you will also notice the expect keyword) but those are not Jasmine tests. More info can be found here: https://stackoverflow.com/a/13213262/1418796

like image 166
pkozlowski.opensource Avatar answered Sep 23 '22 14:09

pkozlowski.opensource


Here is the documentation for expect.

like image 35
jameshfisher Avatar answered Sep 21 '22 14:09

jameshfisher