-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstraw-android-http-plugin-spec.js
94 lines (56 loc) · 2.54 KB
/
straw-android-http-plugin-spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
var describe = window.describe;
var it = window.it;
var expect = window.expect;
var sinon = window.sinon;
var straw = window.straw;
describe('http', function () {
'use strict';
it('exists', function () {
expect(straw).not.toEqual(null);
expect(straw.http).not.toEqual(null);
expect(typeof straw.http).toEqual('object');
});
describe('get', function () {
it('is defined and is a function', function () {
expect(straw.http.get).not.toEqual(null);
expect(typeof straw.http.get).toBe('function');
});
it('invokes straw.execute with appropriate arguments', function () {
var spy = sinon.spy(straw, 'exec');
straw.http.get('http://example.com/', 123, 'shift_jis');
expect(spy.getCall(0).args[0]).toBe('http');
expect(spy.getCall(0).args[1]).toBe('get');
expect(typeof spy.getCall(0).args[2]).toBe('object');
expect(spy.getCall(0).args[2].url).toBe('http://example.com/');
expect(spy.getCall(0).args[2].timeout).toBe(123);
expect(spy.getCall(0).args[2].charset).toBe('shift_jis');
straw.exec.restore();
});
describe('success handler', function () {
it('will be called, when plugin execution succeeded', function () {
var spy = sinon.spy(straw.JS_TO_NATIVE_INTERFACE, 'exec');
var spy2 = sinon.spy();
var spy3 = sinon.spy();
straw.http.get('http://example.com/', 123, 'shift_jis').done(spy2).fail(spy3);
var callbackId = spy.getCall(0).args[3];
straw.NATIVE_TO_JS_INTERFACE.exec(callbackId, true, {}, false);
expect(spy2.calledOnce).toBe(true);
expect(spy3.called).toBe(false);
spy.restore();
});
});
describe('failure handler', function () {
it('will be called, when plugin execution failed', function () {
var spy = sinon.spy(straw.JS_TO_NATIVE_INTERFACE, 'exec');
var spy2 = sinon.spy();
var spy3 = sinon.spy();
straw.http.get('http://example.com/', 123, 'shift_jis').done(spy2).fail(spy3);
var callbackId = spy.getCall(0).args[3];
straw.NATIVE_TO_JS_INTERFACE.exec(callbackId, false, {}, false);
expect(spy2.called).toBe(false);
expect(spy3.calledOnce).toBe(true);
spy.restore();
});
});
});
});