Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit ba162d5

Browse files
test($compile): check that $onInit is called correctly for ES6 classes
1 parent c166a23 commit ba162d5

File tree

1 file changed

+19
-14
lines changed

1 file changed

+19
-14
lines changed

test/ng/compileSpec.js

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4244,6 +4244,22 @@ describe('$compile', function() {
42444244
if (!/chrome/i.test(navigator.userAgent)) return;
42454245
/*jshint -W061 */
42464246
var controllerCalled = false;
4247+
var Controller = eval(
4248+
"class Foo {\n" +
4249+
" constructor($scope) {}\n" +
4250+
" $onInit() { this.check(); }\n" +
4251+
" check() {\n" +
4252+
" expect(this.data).toEqualData({\n" +
4253+
" 'foo': 'bar',\n" +
4254+
" 'baz': 'biz'\n" +
4255+
" });\n" +
4256+
" expect(this.str).toBe('Hello, world!');\n" +
4257+
" expect(this.fn()).toBe('called!');\n" +
4258+
" controllerCalled = true;\n" +
4259+
" }\n" +
4260+
"}");
4261+
spyOn(Controller.prototype, '$onInit');
4262+
42474263
module(function($compileProvider) {
42484264
$compileProvider.directive('fooDir', valueFn({
42494265
template: '<p>isolate</p>',
@@ -4252,20 +4268,7 @@ describe('$compile', function() {
42524268
'str': '@dirStr',
42534269
'fn': '&dirFn'
42544270
},
4255-
controller: eval(
4256-
"class Foo {" +
4257-
" constructor($scope) {}" +
4258-
" check() {" +
4259-
" expect(this.data).toEqualData({" +
4260-
" 'foo': 'bar'," +
4261-
" 'baz': 'biz'" +
4262-
" });" +
4263-
" expect(this.str).toBe('Hello, world!');" +
4264-
" expect(this.fn()).toBe('called!');" +
4265-
" controllerCalled = true;" +
4266-
" }" +
4267-
"}"
4268-
),
4271+
controller: Controller,
42694272
controllerAs: 'test',
42704273
bindToController: true
42714274
}));
@@ -4280,13 +4283,15 @@ describe('$compile', function() {
42804283
element = $compile('<div foo-dir dir-data="remoteData" ' +
42814284
'dir-str="Hello, {{whom}}!" ' +
42824285
'dir-fn="fn()"></div>')($rootScope);
4286+
expect(Controller.prototype.$onInit).toHaveBeenCalled();
42834287
element.data('$fooDirController').check();
42844288
expect(controllerCalled).toBe(true);
42854289
});
42864290
/*jshint +W061 */
42874291
});
42884292

42894293

4294+
42904295
it('should update @-bindings on controller when bindToController and attribute change observed', function() {
42914296
module(function($compileProvider) {
42924297
$compileProvider.directive('atBinding', valueFn({

0 commit comments

Comments
 (0)