-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.test.js
37 lines (31 loc) · 1.16 KB
/
client.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
const test = require("ava");
const { createService } = require("./client.js");
test("createService() returns an object", async t => {
const service = createService(function noop() {});
t.is(typeof service, "object");
});
test("descendant properties of a service return functions", async t => {
const service = createService(function noop() {});
t.is(typeof service.foo, "function");
t.is(typeof service.foo.bar, "function");
t.is(typeof service.foo.bar.baz, "function");
});
test("function call: receives path & args", async t => {
const service = createService(callHandler);
await service.foo.bar({ name: "World" }, "!");
function callHandler(...args) {
t.deepEqual(this.path, ["foo", "bar"]);
const [ details, punctuation ] = args;
t.deepEqual(details, { name: "World" });
t.deepEqual(punctuation, "!");
}
});
test("function call: returns value", async t => {
const service = createService(callHandler);
const response = await service.foo.bar({ name: "World" }, "!");
t.is(response, "Hello, World!");
function callHandler(...args) {
const [ details, punctuation ] = args;
return `Hello, ${details.name}${punctuation}`;
}
});