Skip to content

Commit c61499c

Browse files
committed
Add tests for when engine is the first param
1 parent 82bd536 commit c61499c

1 file changed

Lines changed: 47 additions & 0 deletions

File tree

tests/engines/google_test.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,35 @@ describe("google", {
134134
]);
135135
});
136136

137+
it("getJson with engine as first parameter (async/await)", async () => {
138+
const response = await getJson(engine, {
139+
api_key: null, // null to support the "coffee" unmetered query
140+
q: "coffee",
141+
});
142+
assertArrayIncludes(Object.keys(response).sort(), [
143+
"organic_results",
144+
"pagination",
145+
"search_information",
146+
"search_metadata",
147+
"search_parameters",
148+
"serpapi_pagination",
149+
]);
150+
});
151+
152+
it("getJson with engine as first parameter (callback)", async () => {
153+
const response = await new Promise<Awaited<ReturnType<typeof getJson>>>(
154+
(res) => getJson(engine, { api_key: null, q: "coffee" }, res),
155+
);
156+
assertArrayIncludes(Object.keys(response).sort(), [
157+
"organic_results",
158+
"pagination",
159+
"search_information",
160+
"search_metadata",
161+
"search_parameters",
162+
"serpapi_pagination",
163+
]);
164+
});
165+
137166
it("getHtml for an unmetered query (async/await)", async () => {
138167
const response = await getHtml({ engine, api_key: null, q: "coffee" });
139168
assertStringIncludes(response, "<html");
@@ -211,6 +240,24 @@ describe("google", {
211240
assertEquals(json["search_metadata"]["status"], "Processing");
212241
});
213242

243+
it("getHtml with engine as first parameter (async/await)", async () => {
244+
const response = await getHtml(engine, { api_key: null, q: "coffee" });
245+
assertStringIncludes(response, "<html");
246+
assertStringIncludes(response, "<body");
247+
assertStringIncludes(response, "</body>");
248+
assertStringIncludes(response, "</html>");
249+
});
250+
251+
it("getHtml with engine as first parameter (callback)", async () => {
252+
const response = await new Promise<Awaited<ReturnType<typeof getHtml>>>(
253+
(res) => getHtml(engine, { api_key: null, q: "coffee" }, res),
254+
);
255+
assertStringIncludes(response, "<html");
256+
assertStringIncludes(response, "<body");
257+
assertStringIncludes(response, "</body>");
258+
assertStringIncludes(response, "</html>");
259+
});
260+
214261
// get(Json|Html)BySearchId always require a valid API key even for unmetered queries
215262
it("get(Json|Html)BySearchId", {
216263
ignore: !HAS_API_KEY,

0 commit comments

Comments
 (0)