angular-cn/tools/transpiler/spec/classes_spec.js

87 lines
1.6 KiB
JavaScript
Raw Normal View History

import {ddescribe, describe, it, expect} from 'test_lib/test_lib';
import {CONST} from './fixtures/annotations';
2014-09-25 17:30:10 -04:00
// Constructor
// Define fields
class Foo {
constructor(a, b) {
this.a = a;
this.b = b;
}
sum() {
return this.a + this.b;
}
}
class SubFoo extends Foo {
constructor(a, b) {
this.c = 3;
super(a, b);
}
}
class Const {
@CONST
constructor(a:number) {
this.a = a;
}
}
class SubConst extends Const {
@CONST
constructor(a:number, b:number) {
super(a);
this.b = b;
}
}
class HasGetters {
get getter():string {
return 'getter';
}
static get staticGetter():string {
return 'getter';
}
}
export function main() {
describe('classes', function() {
it('should work', function() {
var foo = new Foo(2, 3);
2014-09-25 17:30:10 -04:00
expect(foo.a).toBe(2);
expect(foo.b).toBe(3);
expect(foo.sum()).toBe(5);
});
it('@CONST should be transpiled to a const constructor', function() {
var subConst = new SubConst(1, 2);
expect(subConst.a).toBe(1);
expect(subConst.b).toBe(2);
});
describe('inheritance', function() {
it('should support super call', function () {
var subFoo = new SubFoo(1, 2);
expect(subFoo.a).toBe(1);
expect(subFoo.b).toBe(2);
expect(subFoo.c).toBe(3);
});
});
describe("getters", function () {
it("should call instance getters", function () {
var obj = new HasGetters();
expect(obj.getter).toEqual('getter');
});
it("should call static getters", function () {
expect(HasGetters.staticGetter).toEqual('getter');
});
});
});
2014-09-25 17:30:10 -04:00
}