forked from dwmkerr/angular-modal-service
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparameters.spec.js
87 lines (65 loc) · 2.04 KB
/
parameters.spec.js
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
describe('parameters', () => {
let ModalService = null;
let rootScope = null;
angular.module('parametertests', ['angularModalService'])
.controller('ValidController', ($scope, close) => {
$scope.close = close;
});
beforeEach(() => {
angular.mock.module('parametertests');
inject((_ModalService_, $rootScope) => {
ModalService = _ModalService_;
rootScope = $rootScope;
});
});
it('should fail if there is no controller specified', function(done) {
ModalService.showModal({
templateUrl: "some/template.html"
// note, no controller is specified, so we should fail.
}).then(function(modal) {
// We should never get here!
expect(true).toBe(false);
done();
}).catch(function(error) {
expect(error).toEqual("No controller has been specified.");
done();
});
rootScope.$apply();
});
it('should fail if there is no template or template url specified', function(done) {
ModalService.showModal({
controller: "SomeController"
// note, no template or template url is specified, so we should fail.
}).then(function(modal) {
// We should never get here!
expect(true).toBe(false);
done();
}).catch(function(error) {
expect(error).toEqual("No template or templateUrl has been specified.");
done();
});
rootScope.$apply();
});
it('should accept the template provided as a string', function(done) {
ModalService.showModal({
controller: "ValidController",
template: "<div>A template</div>"
}).then(function(modal) {
expect(modal.element.html()).toBe("A template");
done();
});
rootScope.$apply();
});
it('should accept the controller provided as a function', function(done) {
ModalService.showModal({
controller: function($scope){
$scope.test = "here";
},
template: "<div>A template</div>"
}).then(function(modal) {
expect(modal.element.html()).toBe("A template");
done();
});
rootScope.$apply();
});
});