1 Star 0 Fork 1

HuangWanddy/search-engine-tool

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
searchEngineTool.test.js 2.89 KB
一键复制 编辑 原始数据 按行查看 历史
brzhang 提交于 2023-06-24 19:29 . feat: 测试用例
const searchEngineTool = require("./searchEngineTool");
describe("searchEngineTool", () => {
test("should return search results from google", async () => {
const query = "深圳天气";
const engine = "google";
const results = await searchEngineTool(query, engine);
expect(results).toHaveLength(5);
results.forEach((result) => {
expect(result).toHaveProperty("href");
expect(result).toHaveProperty("title");
expect(result).toHaveProperty("abstract");
// expect(result.href).not.toBeNull();
// expect(result.title).not.toBeNull();
// expect(result.abstract).not.toBeNull();
expect(result.href).not.toBe("");
expect(result.title).not.toBe("");
expect(result.abstract).not.toBe("");
});
});
test("should return search results from bing", async () => {
const query = "深圳天气";
const engine = "bing";
const results = await searchEngineTool(query, engine);
expect(results).toHaveLength(5);
results.forEach((result) => {
expect(result).toHaveProperty("href");
expect(result).toHaveProperty("title");
expect(result).toHaveProperty("abstract");
// expect(result.href).not.toBeNull();
// expect(result.title).not.toBeNull();
// expect(result.abstract).not.toBeNull();
expect(result.href).not.toBe("");
expect(result.title).not.toBe("");
expect(result.abstract).not.toBe("");
});
});
test("should return search results from yahoo", async () => {
const query = "深圳天气";
const engine = "yahoo";
const results = await searchEngineTool(query, engine);
expect(results).toHaveLength(5);
results.forEach((result) => {
expect(result).toHaveProperty("href");
expect(result).toHaveProperty("title");
expect(result).toHaveProperty("abstract");
expect(result.href).not.toBe("");
expect(result.title).not.toBe("");
expect(result.abstract).not.toBe("");
});
});
test("should return search results from duckduckgo", async () => {
const query = "深圳天气";
const engine = "duckduckgo";
const results = await searchEngineTool(query, engine);
expect(results).toHaveLength(5);
results.forEach((result) => {
expect(result).toHaveProperty("href");
expect(result).toHaveProperty("title");
expect(result).toHaveProperty("abstract");
// expect(result.href).not.toBeNull();
// expect(result.title).not.toBeNull();
// expect(result.abstract).not.toBeNull();
expect(result.href).not.toBe("");
expect(result.title).not.toBe("");
expect(result.abstract).not.toBe("");
});
});
test("should throw an error for invalid search engine", async () => {
const query = "test query";
const engine = "invalid_engine";
await expect(searchEngineTool(query, engine)).rejects.toThrow(
"Invalid search engine specified."
);
});
});
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/wanddyh/search-engine-tool.git
git@gitee.com:wanddyh/search-engine-tool.git
wanddyh
search-engine-tool
search-engine-tool
main

搜索帮助