Skip to content

Commit 3b4bc0c

Browse files
committed
Add tests for shorthand options
1 parent 144d2e8 commit 3b4bc0c

File tree

2 files changed

+139
-3
lines changed

2 files changed

+139
-3
lines changed

test/controllers/options.js

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ angular.module('options-classy', ['classy']).classy.options.controller = {
77
addToScope: false,
88
addToClass: false
99
}
10-
}
10+
};
1111

1212
angular.module('options-classy').classy.controller({
1313
name: 'optionsOne',
@@ -67,3 +67,62 @@ angular.module('options-classy').classy.controller({
6767
}
6868
}
6969
});
70+
71+
72+
angular.module('options-classy-shorthand', ['classy']).classy.options.controller = {
73+
addToScope: false,
74+
addToClass: false
75+
};
76+
77+
angular.module('options-classy-shorthand').classy.controller({
78+
name: 'optionsOne',
79+
inject: ['$scope'],
80+
81+
data: {
82+
foo: '"foo"',
83+
bar: '"bar"'
84+
},
85+
86+
init: function() {
87+
this.baz = 'baz';
88+
this.$.baz = 'baz';
89+
},
90+
91+
methods: {
92+
fooMethod: function() {
93+
return;
94+
},
95+
barMethod: function() {
96+
return;
97+
}
98+
}
99+
});
100+
101+
angular.module('options-classy-shorthand').classy.controller({
102+
name: 'optionsTwo',
103+
// Override module options
104+
__options: {
105+
addToScope: true,
106+
addToClass: false
107+
},
108+
inject: ['$scope'],
109+
110+
data: {
111+
foo: '"foo"',
112+
bar: '"bar"'
113+
},
114+
115+
init: function() {
116+
this.baz = 'baz';
117+
this.$.baz = 'baz';
118+
},
119+
120+
methods: {
121+
fooMethod: function() {
122+
return;
123+
},
124+
barMethod: function() {
125+
return;
126+
}
127+
}
128+
});

test/unit/optionsSpec.js

Lines changed: 79 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,15 @@
5050
ctrl = $controller(ctrlName, { $scope: scope });
5151
}));
5252

53-
it('should not have any properties from data', function () {
53+
it('should have `data` properties on scope but not directly on controller', function () {
5454
expect(scope.foo).toBeDefined();
5555
expect(ctrl.foo).toBeUndefined();
5656

5757
expect(scope.bar).toBeDefined();
5858
expect(ctrl.bar).toBeUndefined();
5959
});
6060

61-
it('should not have any properties from methods', function () {
61+
it('should not have methods on scope but does have methods directly on controller', function () {
6262
expect(scope.fooMethod).toBeUndefined();
6363
expect(ctrl.fooMethod).toBeDefined();
6464

@@ -78,4 +78,81 @@
7878

7979
});
8080

81+
describe('Classy Plugin Options', function () {
82+
83+
beforeEach(module('options-classy-shorthand'));
84+
85+
describe('first controller', function() {
86+
var ctrl, scope;
87+
var ctrlName = 'optionsOne';
88+
89+
beforeEach(inject(function ($controller, $rootScope) {
90+
scope = $rootScope.$new();
91+
ctrl = $controller(ctrlName, { $scope: scope });
92+
}));
93+
94+
it('should not have any properties from data', function () {
95+
expect(scope.foo).toBeUndefined();
96+
expect(ctrl.foo).toBeUndefined();
97+
98+
expect(scope.bar).toBeUndefined();
99+
expect(ctrl.bar).toBeUndefined();
100+
});
101+
102+
it('should not have any properties from methods', function () {
103+
expect(scope.fooMethod).toBeUndefined();
104+
expect(ctrl.fooMethod).toBeUndefined();
105+
106+
expect(scope.barMethod).toBeUndefined();
107+
expect(ctrl.barMethod).toBeUndefined();
108+
});
109+
110+
111+
it('should have `baz` property on scope and class', function () {
112+
expect(scope.baz).toBeDefined();
113+
expect(ctrl.baz).toBeDefined();
114+
});
115+
116+
117+
});
118+
119+
120+
describe('second controller', function() {
121+
var ctrl, scope;
122+
var ctrlName = 'optionsTwo';
123+
124+
beforeEach(inject(function ($controller, $rootScope) {
125+
scope = $rootScope.$new();
126+
ctrl = $controller(ctrlName, { $scope: scope });
127+
}));
128+
129+
it('should have `data` properties on scope but not directly on controller', function () {
130+
expect(scope.foo).toBeDefined();
131+
expect(ctrl.foo).toBeUndefined();
132+
133+
expect(scope.bar).toBeDefined();
134+
expect(ctrl.bar).toBeUndefined();
135+
});
136+
137+
it('should have methods on scope but not directly on controller', function () {
138+
expect(scope.fooMethod).toBeDefined();
139+
expect(ctrl.fooMethod).toBeUndefined();
140+
141+
expect(scope.barMethod).toBeDefined();
142+
expect(ctrl.barMethod).toBeUndefined();
143+
});
144+
145+
146+
it('should have `baz` property on scope and class', function () {
147+
expect(scope.baz).toBeDefined();
148+
expect(ctrl.baz).toBeDefined();
149+
});
150+
151+
152+
});
153+
154+
155+
});
156+
157+
81158
}());

0 commit comments

Comments
 (0)