-
Notifications
You must be signed in to change notification settings - Fork 59
Expand file tree
/
Copy pathhttp.test.js
More file actions
59 lines (53 loc) · 1.81 KB
/
http.test.js
File metadata and controls
59 lines (53 loc) · 1.81 KB
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
'use strict';
define(['ably', 'shared_helper', 'chai'], function (Ably, Helper, chai) {
var rest;
var expect = chai.expect;
describe('rest/http/fetch', function () {
this.timeout(60 * 1000);
let initialXhrSupported;
before(function (done) {
const helper = Helper.forHook(this);
initialXhrSupported = Ably.Rest.Platform.Config.xhrSupported;
Ably.Rest.Platform.Config.xhrSupported = false;
helper.setupApp(function () {
rest = helper.AblyRest();
done();
});
});
after((done) => {
Ably.Rest.Platform.Config.xhrSupported = initialXhrSupported;
done();
});
/** @nospec */
it('Should use fetch when XHR is not supported', function (done) {
let oldFetch = window.fetch;
window.fetch = () => {
done();
window.fetch = oldFetch;
};
const channel = rest.channels.get('http_test_channel');
channel.publish('test', 'Testing fetch support');
});
/** @nospec */
it('Should succeed in using fetch to publish a message', function (done) {
const channel = rest.channels.get('http_test_channel');
Helper.whenPromiseSettles(channel.publish('test', 'Testing fetch support'), (err) => {
expect(err).to.not.exist;
done();
});
});
/**
* RTL6b talks about a callback which should receive an error object (which what we're doing here), but suggests to test other things.
* This test simply tests that with fetch API we're still receiving an error, so it's probably @nospec.
*
* @nospec
*/
it('Should pass errors correctly', function (done) {
const channel = rest.channels.get('');
Helper.whenPromiseSettles(channel.publish('test', 'Invalid message'), (err) => {
expect(err).to.exist;
done();
});
});
});
});