2014-11-25 18:16:53 -05:00
|
|
|
import {describe, it, iit, ddescribe, expect, tick, async, SpyObject, beforeEach} from 'test_lib/test_lib';
|
2015-02-02 19:25:34 -05:00
|
|
|
import {MapWrapper, ListWrapper} from 'facade/src/collection';
|
|
|
|
import {PromiseWrapper} from 'facade/src/async';
|
|
|
|
import {IMPLEMENTS, proxy} from 'facade/src/lang';
|
2014-10-29 14:26:52 -04:00
|
|
|
|
|
|
|
class TestObj {
|
2014-11-22 00:19:23 -05:00
|
|
|
prop;
|
2014-10-29 14:26:52 -04:00
|
|
|
constructor(prop) {
|
|
|
|
this.prop = prop;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-25 18:16:53 -05:00
|
|
|
@proxy
|
|
|
|
@IMPLEMENTS(TestObj)
|
|
|
|
class SpyTestObj extends SpyObject {noSuchMethod(m){return super.noSuchMethod(m)}}
|
|
|
|
|
2014-10-29 14:26:52 -04:00
|
|
|
export function main() {
|
2014-11-17 20:39:39 -05:00
|
|
|
describe('test_lib', () => {
|
|
|
|
describe('equality', () => {
|
|
|
|
it('should structurally compare objects', () => {
|
|
|
|
var expected = new TestObj(new TestObj({'one' : [1,2]}));
|
|
|
|
var actual = new TestObj(new TestObj({'one' : [1,2]}));
|
|
|
|
var falseActual = new TestObj(new TestObj({'one' : [1,3]}));
|
2014-10-29 14:26:52 -04:00
|
|
|
|
|
|
|
expect(actual).toEqual(expected);
|
|
|
|
expect(falseActual).not.toEqual(expected);
|
|
|
|
});
|
2014-11-11 20:33:47 -05:00
|
|
|
|
2015-01-27 17:52:15 -05:00
|
|
|
it('should work for arrays of string maps', () => {
|
2014-11-11 20:33:47 -05:00
|
|
|
expect([{'a':'b'}]).toEqual([{'a':'b'}]);
|
|
|
|
});
|
2015-01-27 17:52:15 -05:00
|
|
|
|
|
|
|
it('should work for arrays of real maps', () => {
|
|
|
|
expect([MapWrapper.createFromStringMap({'a':'b'})]).toEqual([MapWrapper.createFromStringMap({'a':'b'})]);
|
|
|
|
expect([MapWrapper.createFromStringMap({'a':'b'})]).not.toEqual([MapWrapper.createFromStringMap({'a':'c'})]);
|
|
|
|
});
|
2014-10-29 14:26:52 -04:00
|
|
|
});
|
2014-11-17 20:39:39 -05:00
|
|
|
|
|
|
|
describe('toEqual for Maps', () => {
|
|
|
|
it('should detect equality for same reference', () => {
|
|
|
|
var m1 = MapWrapper.createFromStringMap({'a': 1});
|
|
|
|
expect(m1).toEqual(m1);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should detect equality for same content', () => {
|
|
|
|
expect(MapWrapper.createFromStringMap({'a': 1})).toEqual(MapWrapper.createFromStringMap({'a': 1}));
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should detect missing entries', () => {
|
|
|
|
expect(MapWrapper.createFromStringMap({'a': 1})).not.toEqual(MapWrapper.createFromStringMap({}));
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should detect different values', () => {
|
|
|
|
expect(MapWrapper.createFromStringMap({'a': 1})).not.toEqual(MapWrapper.createFromStringMap({'a': 2}));
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should detect additional entries', () => {
|
|
|
|
expect(MapWrapper.createFromStringMap({'a': 1})).not.toEqual(MapWrapper.createFromStringMap({'a': 1, 'b': 1}));
|
|
|
|
});
|
|
|
|
});
|
2014-11-25 18:16:53 -05:00
|
|
|
|
|
|
|
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);
|
|
|
|
});
|
|
|
|
});
|
2014-10-29 14:26:52 -04:00
|
|
|
});
|
|
|
|
}
|