UNPKG

1.12 kBMarkdownView Raw
1# Intro
2
3Unit testing and mocking AngularJs requires a lot of boilerplate code:
4```js
5describe('typical test', function () {
6 var foo;
7 beforeEach(function () {
8 angular.mock.module('A');
9 // other modules
10 });
11 beforeEach(inject(function (_foo_) {
12 foo = _foo_;
13 }));
14 it('finally a test', function () {
15 expect(foo).toEqual('bar');
16 });
17});
18```
19
20{%= name %} makes testing simple modules a breeze.
21Just list which modules you would like to load, which values / services / etc.
22you would like to inject and then start testing. Same test as above using {%= name %}
23is much shorter and clearer:
24```js
25ngDescribe({
26 modules: 'A',
27 tests: function (foo) {
28 it('finally a test', function () {
29 expect(foo).toEqual('bar');
30 });
31 });
32});
33```
34{%= name %} can inject dependencies, mock modules, set configs, create controllers, scopes, and
35even html fragments. For more details, continue reading. We also showed this library at AngularJS NYC
36meetup, the slides are at [slides.com/bahmutov/ng-describe](http://slides.com/bahmutov/ng-describe).