Skip to content

Commit c759d80

Browse files
committed
Updated test
1 parent 7058113 commit c759d80

File tree

2 files changed

+70
-2
lines changed

2 files changed

+70
-2
lines changed

index.test-d.ts

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
// Licensed to Elasticsearch B.V under one or more agreements.
2+
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
3+
// See the LICENSE file in the project root for more information
4+
5+
import { expectType, expectError } from 'tsd'
6+
import { Client } from '@elastic/elasticsearch'
7+
import Mock, { MockPattern } from './'
8+
9+
const mock = new Mock()
10+
const client = new Client({
11+
node: 'http://localhost:9200',
12+
Connection: mock.getConnection()
13+
})
14+
15+
mock.add({
16+
method: 'GET',
17+
path: '/'
18+
}, params => {
19+
expectType<MockPattern>(params)
20+
return { status: 'ok' }
21+
})
22+
23+
mock.add({
24+
method: 'GET',
25+
path: '/',
26+
querystring: { pretty: 'true' }
27+
}, params => {
28+
expectType<MockPattern>(params)
29+
return { status: 'ok' }
30+
})
31+
32+
mock.add({
33+
method: 'POST',
34+
path: '/',
35+
querystring: { pretty: 'true' },
36+
body: { foo: 'bar' }
37+
}, params => {
38+
expectType<MockPattern>(params)
39+
return { status: 'ok' }
40+
})
41+
42+
mock.add({
43+
method: 'GET',
44+
path: '/'
45+
}, params => {
46+
expectType<MockPattern>(params)
47+
return 'ok'
48+
})
49+
50+
// querystring should only have string values
51+
expectError(
52+
mock.add({
53+
method: 'GET',
54+
path: '/',
55+
querystring: { pretty: true }
56+
}, () => {
57+
return { status: 'ok' }
58+
})
59+
)
60+
61+
// missing resolver function
62+
expectError(
63+
mock.add({
64+
method: 'GET',
65+
path: '/'
66+
})
67+
)

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"main": "index.js",
66
"types": "index.d.ts",
77
"scripts": {
8-
"test": "standard && ava -v",
8+
"test": "standard && ava -v && tsd",
99
"coverage:report": "nyc ava && nyc report --reporter=lcov && echo \"\n==> open coverage/lcov-report/index.html\"",
1010
"coverage:check": "nyc ava && nyc check-coverage --branches=100 --lines=100 --functions=100 --statements=100"
1111
},
@@ -24,7 +24,8 @@
2424
"@elastic/elasticsearch": "^7.7.0-rc.2",
2525
"ava": "^3.6.0",
2626
"nyc": "^15.0.1",
27-
"standard": "^14.3.3"
27+
"standard": "^14.3.3",
28+
"tsd": "^0.11.0"
2829
},
2930
"dependencies": {
3031
"fast-deep-equal": "^3.1.1",

0 commit comments

Comments
 (0)