forked from willmendesneto/angular-testing-recipes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontrollers.spec.js
More file actions
59 lines (47 loc) · 1.31 KB
/
Copy pathcontrollers.spec.js
File metadata and controls
59 lines (47 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
describe('SampleController', function() {
'use strict';
var $rootScope,
ctrl, scope;
beforeEach(module('myApp'));
beforeEach(inject(function( _$rootScope_, _$controller_) {
$rootScope = _$rootScope_;
scope = $rootScope.$new();
ctrl = _$controller_('SampleController', {
$scope: scope
});
$rootScope.showLogs = false;
}));
it('should expose a property', function() {
expect(ctrl.foo).toBe('bar');
});
it('should expose a method', function() {
ctrl.bar();
expect(ctrl.foo).toBe('baz');
});
it('should have a watcher', function() {
scope.baz = 'foo';
scope.$apply();
expect(ctrl.baz).toBe('foobar');
});
it('should do something on $destroy', function() {
spyOn(ctrl, 'doSomething');
scope.$destroy();
expect(ctrl.doSomething).toHaveBeenCalled();
});
it('should emit an event', function() {
spyOn(scope, '$emit');
ctrl.sendMessage();
expect(scope.$emit).toHaveBeenCalled();
expect(scope.$emit).toHaveBeenCalledWith('sample:message', {
foo: 'bar'
});
});
it('should broadcast an event', function() {
spyOn(scope, '$broadcast');
ctrl.broadcastEvent();
expect(scope.$broadcast).toHaveBeenCalled();
expect(scope.$broadcast).toHaveBeenCalledWith('sample:broadcast', {
foo: 'bar'
});
});
});