feat(test_lib): implement SpyObject

This commit is contained in:
vsavkin
2014-11-25 15:16:53 -08:00
parent 965f70bfbe
commit f06433fb58
7 changed files with 107 additions and 22 deletions

View File

@ -1,6 +1,7 @@
import {describe, it, iit, ddescribe, expect, tick, async} from 'test_lib/test_lib';
import {describe, it, iit, ddescribe, expect, tick, async, SpyObject, beforeEach} from 'test_lib/test_lib';
import {MapWrapper, ListWrapper} from 'facade/collection';
import {PromiseWrapper} from 'facade/async';
import {IMPLEMENTS, proxy} from 'facade/lang';
class TestObj {
prop;
@ -9,6 +10,10 @@ class TestObj {
}
}
@proxy
@IMPLEMENTS(TestObj)
class SpyTestObj extends SpyObject {noSuchMethod(m){return super.noSuchMethod(m)}}
export function main() {
describe('test_lib', () => {
describe('equality', () => {
@ -48,5 +53,29 @@ export function main() {
expect(MapWrapper.createFromStringMap({'a': 1})).not.toEqual(MapWrapper.createFromStringMap({'a': 1, 'b': 1}));
});
});
describe("spy objects", () => {
var spyObj;
beforeEach(() => {
spyObj = new SpyTestObj();
});
it("should pass the runtime check", () => {
var t:TestObj = spyObj;
expect(t).toBeDefined();
});
it("should return a new spy func with no calls", () => {
expect(spyObj.spy("someFunc")).not.toHaveBeenCalled();
});
it("should record function calls", () => {
spyObj.spy("someFunc").andCallFake((a,b) => a + b);
expect(spyObj.someFunc(1,2)).toEqual(3);
expect(spyObj.spy("someFunc")).toHaveBeenCalledWith(1,2);
});
});
});
}