-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
57 lines (47 loc) · 1.64 KB
/
test.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
"use strict";
// Module dependencies
var expect = require("chai").expect;
var requestMock = require("./request-mock.js");
var rewire = require("rewire");
var LamernewsAPI = rewire("./");
LamernewsAPI.__set__("request", requestMock);
describe("LamernewsAPI", function() {
beforeEach(function() {
this.api = new LamernewsAPI("http://echojs.com/api/");
});
describe("#getNews", function() {
it("fetches news asynchronously", function(done) {
this.api.getNews(function(err, response) {
if (err) {
throw err;
}
expect(err).to.be.a("null");
expect(response).to.be.an("object");
expect(response).to.have.keys([
"status", "count", "news"
]);
expect(response.count).to.be.a("number");
expect(response.news).to.be.an("array");
expect(response.status).to.be.a("string");
done();
});
});
});
describe("#query", function() {
it("throws an error if root was not specified", function() {
this.api.root = null;
expect(this.api.query).to.throw(Error);
});
it("queries the given API endpoint", function(done) {
var signature = "/getnews/latest/0/30";
this.api.query(signature, function onDone(err, response) {
if (err) {
throw err;
}
expect(err).to.be.a("null");
expect(response).to.be.an("object");
done();
});
});
});
});