Skip to content

Commit c555996

Browse files
committed
test: use getSuggestionsMock which uses getSuggestions types
1 parent f785ff4 commit c555996

File tree

1 file changed

+21
-8
lines changed

1 file changed

+21
-8
lines changed

test/adapters/autocomplete-adapter.test.ts

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,25 @@ describe("AutoCompleteAdapter", () => {
7676
let server: ActiveServer
7777
let autoCompleteAdapter: AutoCompleteAdapter
7878

79-
async function getResults(
79+
type getSuggestionParams = Parameters<typeof autoCompleteAdapter.getSuggestions>
80+
81+
/** Function that stubs `server.connection.completion` and returns the `autoCompleteAdapter.getSuggestions(...)` */
82+
async function getSuggestionsMock(
8083
items: CompletionItem[],
81-
requestParams: { prefix?: string; point?: Point }
84+
requestParams: Parameters<typeof createRequest>[0],
85+
onDidConvertCompletionItem?: getSuggestionParams[2],
86+
minimumWordLength?: getSuggestionParams[3],
8287
): Promise<ac.AnySuggestion[]> {
83-
sinon.stub(server.connection, "completion").resolves(items)
84-
return autoCompleteAdapter.getSuggestions(server, createRequest(requestParams))
88+
const resultsSandBox = sinon.createSandbox()
89+
resultsSandBox.stub(server.connection, "completion").resolves(items)
90+
const results = autoCompleteAdapter.getSuggestions(
91+
server,
92+
createRequest(requestParams),
93+
onDidConvertCompletionItem,
94+
minimumWordLength,
95+
)
96+
resultsSandBox.restore()
97+
return results
8598
}
8699

87100
beforeEach(() => {
@@ -90,12 +103,12 @@ describe("AutoCompleteAdapter", () => {
90103
})
91104

92105
it("gets AutoComplete suggestions via LSP given an AutoCompleteRequest", async () => {
93-
const results = await getResults(completionItems, { prefix: "" })
106+
const results = await getSuggestionsMock(completionItems, { prefix: "" })
94107
expect(results.length).equals(completionItems.length)
95108
})
96109

97110
it("provides a filtered selection based on the filterKey", async () => {
98-
const results = await getResults(completionItems, { prefix: "lab" })
111+
const results = await getSuggestionsMock(completionItems, { prefix: "lab" })
99112
expect(results.length).equals(2)
100113
expect(results.some((r) => r.displayText === "thisHasFiltertext")).to.be.true
101114
expect(results.some((r) => r.displayText === "label3")).to.be.true
@@ -107,7 +120,7 @@ describe("AutoCompleteAdapter", () => {
107120
{ label: "b" },
108121
{ label: "c", sortText: "a" },
109122
]
110-
const results = await getResults(sortedItems, { prefix: "" })
123+
const results = await getSuggestionsMock(sortedItems, { prefix: "" })
111124

112125
expect(results.length).equals(sortedItems.length)
113126
expect(results[0].displayText).equals("c")
@@ -116,7 +129,7 @@ describe("AutoCompleteAdapter", () => {
116129
})
117130

118131
it("uses the filterText property to arrange completions when there is a prefix", async () => {
119-
const results = await getResults(completionItems, { prefix: "lab" })
132+
const results = await getSuggestionsMock(completionItems, { prefix: "lab" })
120133
expect(results.length).equals(2)
121134
expect(results[0].displayText).equals("label3") // shorter than 'labrador', so expected to be first
122135
expect(results[1].displayText).equals("thisHasFiltertext")

0 commit comments

Comments
 (0)