-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bugsplat.spec.ts
63 lines (55 loc) · 1.61 KB
/
bugsplat.spec.ts
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
import { BugSplat } from "./bugsplat.ts";
import { test, TestSuite } from "https://deno.land/x/test_suite@v0.6.3/mod.ts";
import { Stub, stub } from "https://deno.land/x/mock@v0.9.4/mod.ts";
import { assertEquals } from "https://deno.land/std@0.80.0/testing/asserts.ts";
interface BugSplatSuiteContext {
bugsplat: BugSplat;
fetch: Stub<any>;
}
const database = "fred";
const appName = "my-deno-crasher-test";
const appVersion = "1.0";
const fakeJson = async () => "success!";
let fakeFormData: any;
let fakeFormDataValues: Array<any>;
let fetchStub: Stub<any>;
let formDataStub: Stub<any>;
const bugSplatSuite: TestSuite<BugSplatSuiteContext> = new TestSuite({
name: "BugSplat",
beforeEach(context: BugSplatSuiteContext) {
context.bugsplat = new BugSplat(database, appName, appVersion);
fakeFormDataValues = [];
fakeFormData = <any> {
append: (key: any, value: any) => {
fakeFormDataValues[key] = value;
},
};
formDataStub = stub(context.bugsplat, "_formData", [fakeFormData]);
fetchStub = stub(globalThis, "fetch", [{
status: 200,
json: fakeJson,
}]);
},
});
test(
bugSplatSuite,
"post should call fetch with url, method and body",
(context: BugSplatSuiteContext) => {
const expectedUrl = `https://${database}.bugsplat.com/post/js/`;
const error = new Error("BugSplat rocks");
context.bugsplat.post(error);
assertEquals(fetchStub.calls, [{
args: [
expectedUrl,
{
body: fakeFormData,
method: "POST",
},
],
returned: {
status: 200,
json: fakeJson,
},
}]);
},
);