Skip to content

Commit 8609543

Browse files
ttowncompiledvicb
authored andcommitted
refactor (test/facade): Ts'ify test/facade
Translate AtScript in test/facade to TypeScript
1 parent f83f1ee commit 8609543

File tree

6 files changed

+220
-233
lines changed

6 files changed

+220
-233
lines changed

modules/angular2/test/facade/async_spec.js

Lines changed: 0 additions & 61 deletions
This file was deleted.
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import {
2+
describe,
3+
it,
4+
expect,
5+
beforeEach,
6+
ddescribe,
7+
iit,
8+
xit,
9+
el,
10+
SpyObject,
11+
AsyncTestCompleter,
12+
inject,
13+
IS_DARTIUM
14+
} from 'angular2/test_lib';
15+
16+
import {ObservableWrapper, EventEmitter, PromiseWrapper} from 'angular2/src/facade/async';
17+
18+
export function main() {
19+
describe('EventEmitter', () => {
20+
var emitter: EventEmitter;
21+
22+
beforeEach(() => { emitter = new EventEmitter(); });
23+
24+
it("should call the next callback", inject([AsyncTestCompleter], (async) => {
25+
ObservableWrapper.subscribe(emitter, (value) => {
26+
expect(value).toEqual(99);
27+
async.done();
28+
});
29+
30+
ObservableWrapper.callNext(emitter, 99);
31+
}));
32+
33+
it("should call the throw callback", inject([AsyncTestCompleter], (async) => {
34+
ObservableWrapper.subscribe(emitter, (_) => {}, (error) => {
35+
expect(error).toEqual("Boom");
36+
async.done();
37+
});
38+
ObservableWrapper.callThrow(emitter, "Boom");
39+
}));
40+
41+
it("should work when no throw callback is provided", inject([AsyncTestCompleter], (async) => {
42+
ObservableWrapper.subscribe(emitter, (_) => {}, (_) => { async.done(); });
43+
ObservableWrapper.callThrow(emitter, "Boom");
44+
}));
45+
46+
it("should call the return callback", inject([AsyncTestCompleter], (async) => {
47+
ObservableWrapper.subscribe(emitter, (_) => {}, (_) => {}, () => { async.done(); });
48+
49+
ObservableWrapper.callReturn(emitter);
50+
}));
51+
52+
it("should subscribe to the wrapper asynchronously", () => {
53+
var called = false;
54+
ObservableWrapper.subscribe(emitter, (value) => { called = true; });
55+
56+
ObservableWrapper.callNext(emitter, 99);
57+
expect(called).toBe(false);
58+
});
59+
60+
// TODO: vsavkin: add tests cases
61+
// should call dispose on the subscription if generator returns {done:true}
62+
// should call dispose on the subscription on throw
63+
// should call dispose on the subscription on return
64+
});
65+
}

modules/angular2/test/facade/collection_spec.js

Lines changed: 0 additions & 112 deletions
This file was deleted.
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
import {describe, it, expect, beforeEach, ddescribe, iit, xit} from 'angular2/test_lib';
2+
3+
import {List, ListWrapper, StringMap, StringMapWrapper} from 'angular2/src/facade/collection';
4+
5+
export function main() {
6+
describe('ListWrapper', () => {
7+
var l: List<int>;
8+
9+
describe('splice', () => {
10+
it('should remove sublist of given length and return it', () => {
11+
var list = [1, 2, 3, 4, 5, 6];
12+
expect(ListWrapper.splice(list, 1, 3)).toEqual([2, 3, 4]);
13+
expect(list).toEqual([1, 5, 6]);
14+
});
15+
16+
it('should support negative start', () => {
17+
var list = [1, 2, 3, 4, 5, 6];
18+
expect(ListWrapper.splice(list, -5, 3)).toEqual([2, 3, 4]);
19+
expect(list).toEqual([1, 5, 6]);
20+
});
21+
});
22+
23+
describe('fill', () => {
24+
beforeEach(() => { l = [1, 2, 3, 4]; });
25+
26+
it('should fill the whole list if neither start nor end are specified', () => {
27+
ListWrapper.fill(l, 9);
28+
expect(l).toEqual([9, 9, 9, 9]);
29+
});
30+
31+
it('should fill up to the end if end is not specified', () => {
32+
ListWrapper.fill(l, 9, 1);
33+
expect(l).toEqual([1, 9, 9, 9]);
34+
});
35+
36+
it('should support negative start', () => {
37+
ListWrapper.fill(l, 9, -1);
38+
expect(l).toEqual([1, 2, 3, 9]);
39+
});
40+
41+
it('should support negative end', () => {
42+
ListWrapper.fill(l, 9, -2, -1);
43+
expect(l).toEqual([1, 2, 9, 4]);
44+
});
45+
});
46+
47+
describe('slice', () => {
48+
beforeEach(() => { l = [1, 2, 3, 4]; });
49+
50+
it('should return the whole list if neither start nor end are specified',
51+
() => { expect(ListWrapper.slice(l)).toEqual([1, 2, 3, 4]); });
52+
53+
it('should return up to the end if end is not specified',
54+
() => { expect(ListWrapper.slice(l, 1)).toEqual([2, 3, 4]); });
55+
56+
it('should support negative start', () => { expect(ListWrapper.slice(l, -1)).toEqual([4]); });
57+
58+
it('should support negative end',
59+
() => { expect(ListWrapper.slice(l, -3, -1)).toEqual([2, 3]); });
60+
});
61+
});
62+
63+
describe('StringMapWrapper', () => {
64+
describe('equals', () => {
65+
it('should return true when comparing empty maps',
66+
() => { expect(StringMapWrapper.equals({}, {})).toBe(true); });
67+
68+
it('should return true when comparing the same map', () => {
69+
var m1 = {'a': 1, 'b': 2, 'c': 3};
70+
expect(StringMapWrapper.equals(m1, m1)).toBe(true);
71+
});
72+
73+
it('should return true when comparing different maps with the same keys and values', () => {
74+
var m1 = {'a': 1, 'b': 2, 'c': 3};
75+
var m2 = {'a': 1, 'b': 2, 'c': 3};
76+
expect(StringMapWrapper.equals(m1, m2)).toBe(true);
77+
});
78+
79+
it('should return false when comparing maps with different numbers of keys', () => {
80+
var m1 = {'a': 1, 'b': 2, 'c': 3};
81+
var m2 = {'a': 1, 'b': 2, 'c': 3, 'd': 4};
82+
expect(StringMapWrapper.equals(m1, m2)).toBe(false);
83+
expect(StringMapWrapper.equals(m2, m1)).toBe(false);
84+
});
85+
86+
it('should return false when comparing maps with different keys', () => {
87+
var m1 = {'a': 1, 'b': 2, 'c': 3};
88+
var m2 = {'a': 1, 'b': 2, 'CC': 3};
89+
expect(StringMapWrapper.equals(m1, m2)).toBe(false);
90+
expect(StringMapWrapper.equals(m2, m1)).toBe(false);
91+
});
92+
93+
it('should return false when comparing maps with different values', () => {
94+
var m1 = {'a': 1, 'b': 2, 'c': 3};
95+
var m2 = {'a': 1, 'b': 20, 'c': 3};
96+
expect(StringMapWrapper.equals(m1, m2)).toBe(false);
97+
expect(StringMapWrapper.equals(m2, m1)).toBe(false);
98+
});
99+
});
100+
});
101+
}

0 commit comments

Comments
 (0)