feat: 增加 toEqual 方法替换 toMatchObject 方法对对象数组进行判断

This commit is contained in:
zhangxiangliang 2020-08-24 00:49:46 +08:00
parent cafab0ca63
commit d5abedfa82
4 changed files with 36 additions and 39 deletions

View File

@ -15,15 +15,15 @@ describe("【网易】股票代码接口", () => {
it("需要获取的股票代码组", async () => {
await expect(Netease.getStocks(["SH510500"]))
.resolves
.toMatchObject([{ code: "SH510500", name: "500ETF" }]);
await expect(Netease.getStocks([]))
.resolves
.toMatchObject([]);
.toEqual(expect.arrayContaining([expect.objectContaining({ code: "SH510500", name: "500ETF" })]));
await expect(Netease.getStocks(["SZ510500"]))
.resolves
.toMatchObject([{ code: "SZ510500", name: "---" }]);
.toEqual(expect.arrayContaining([expect.objectContaining({ code: "SZ510500", name: "---" })]));
await expect(Netease.getStocks([]))
.resolves
.toEqual([]);
});
it("搜索股票代码", async () => {

View File

@ -14,31 +14,31 @@ describe("【新浪】股票代码接口", () => {
it("需要获取的股票代码组", async () => {
await expect(Sina.getStocks(["SH510500"]))
.resolves
.toMatchObject([{ code: "SH510500", name: "500ETF" }]);
await expect(Sina.getStocks([]))
.resolves
.toMatchObject([]);
.toEqual(expect.arrayContaining([expect.objectContaining({ code: "SH510500", name: "500ETF" })]));
await expect(Sina.getStocks(["SZ510500"]))
.resolves
.toMatchObject([{ code: "SZ510500", name: "---" }]);
.toEqual(expect.arrayContaining([expect.objectContaining({ code: "SZ510500", name: "---" })]));
await expect(Sina.getStocks([]))
.resolves
.toEqual([]);
});
it("搜索股票代码", async () => {
await expect(Sina.searchStocks("格力电器"))
.resolves
.toMatchObject([{ code: "SZ000651", name: "格力电器" }]);
.toEqual(expect.arrayContaining([expect.objectContaining({ code: "SZ000651", name: "格力电器" })]));
await expect(Sina.searchStocks("贵州茅台"))
.resolves
.toMatchObject([{ code: "SH600519", name: "贵州茅台" }]);
.toEqual(expect.arrayContaining([expect.objectContaining({ code: "SH600519", name: "贵州茅台" })]));
await expect(Sina.searchStocks("安踏体育"))
.resolves
.toMatchObject([
{ code: expect.stringMatching(".*[02020|ANPDY].*"), name: expect.stringMatching(".*[安踏体育|\-].*") },
{ code: expect.stringMatching(".*[02020|ANPDY].*"), name: expect.stringMatching(".*[安踏体育|\-].*") },
]);
.toEqual(expect.arrayContaining([
expect.objectContaining({ code: "HK02020", name: "安踏体育" }),
expect.objectContaining({ code: "USANPDF", name: "安踏" }),
]));
});
});

View File

@ -19,32 +19,31 @@ describe("【腾讯】股票代码接口", () => {
it("需要获取的股票代码组", async () => {
await expect(Tencent.getStocks(["SH510500"]))
.resolves
.toMatchObject([{ code: "SH510500", name: "500ETF" }]);
.toEqual(expect.arrayContaining([expect.objectContaining({ code: "SH510500", name: "500ETF" })]));
await expect(Tencent.getStocks(["SZ510500"]))
.resolves
.toMatchObject([{ code: "SZ510500", name: "---" }]);
.toEqual(expect.arrayContaining([expect.objectContaining({ code: "SZ510500", name: "---" })]));
await expect(Tencent.getStocks([]))
.resolves
.toMatchObject([]);
.toEqual([]);
});
it("搜索股票代码", async () => {
await expect(Tencent.searchStocks("格力电器"))
.resolves
.toMatchObject([{ code: "SZ000651", name: "格力电器" }]);
.toEqual(expect.arrayContaining([expect.objectContaining({ code: "SZ000651", name: "格力电器" })]));
await expect(Tencent.searchStocks("贵州茅台"))
.resolves
.toMatchObject([{ code: "SH600519", name: "贵州茅台" }]);
.toEqual(expect.arrayContaining([expect.objectContaining({ code: "SH600519", name: "贵州茅台" })]));
await expect(Tencent.searchStocks("安踏体育"))
.resolves
.toMatchObject([
{ code: expect.stringMatching(".*[02020|ANPDY].*"), name: expect.stringMatching(".*[安踏体育|\-].*") },
{ code: expect.stringMatching(".*[02020|ANPDY].*"), name: expect.stringMatching(".*[安踏体育|\-].*") },
]);
.toEqual(expect.arrayContaining([
expect.objectContaining({ code: "HK02020", name: "安踏体育" }),
expect.objectContaining({ code: "USANPDY", name: "安踏体育" }),
]));
});
});

View File

@ -21,33 +21,31 @@ describe("【雪球】股票代码接口", () => {
it("需要获取的股票代码组", async () => {
await expect(Xueqiu.getStocks(["SH510500"]))
.resolves
.toMatchObject([{ code: "SH510500", name: "中证500ETF" }]);
.toEqual(expect.arrayContaining([expect.objectContaining({ code: "SH510500", name: "中证500ETF" })]));
await expect(Xueqiu.getStocks(["SZ510500"]))
.resolves
.toMatchObject([{ code: "SZ510500", name: "---" }]);
.toEqual(expect.arrayContaining([expect.objectContaining({ code: "SZ510500", name: "---" })]));
await expect(Xueqiu.getStocks([]))
.resolves
.toMatchObject([]);
.toEqual([]);
});
it("搜索股票代码", async () => {
await expect(Xueqiu.searchStocks("格力电器"))
.resolves
.toMatchObject([{ code: "SZ000651", name: "格力电器" }]);
.toEqual(expect.arrayContaining([expect.objectContaining({ code: "SZ000651", name: "格力电器" })]));
await expect(Xueqiu.searchStocks("贵州茅台"))
.resolves
.toMatchObject([{ code: "SH600519", name: "贵州茅台" }]);
.toEqual(expect.arrayContaining([expect.objectContaining({ code: "SH600519", name: "贵州茅台" })]));
await expect(Xueqiu.searchStocks("安踏体育"))
.resolves
.toMatchObject([
{ code: expect.stringMatching(".*[02020|ANPDY].*"), name: expect.stringMatching(".*[安踏体育|\-].*") },
{ code: expect.stringMatching(".*[02020|ANPDY].*"), name: expect.stringMatching(".*[安踏体育|\-].*") },
{ code: expect.stringMatching(".*[02020|ANPDY].*"), name: expect.stringMatching(".*[安踏体育|\-].*") },
{ code: expect.stringMatching(".*[02020|ANPDY].*"), name: expect.stringMatching(".*[安踏体育|\-].*") },
]);
.toEqual(expect.arrayContaining([
expect.objectContaining({ code: "HK02020", name: "安踏体育" }),
expect.objectContaining({ code: "USANPDY", name: "安踏体育ADR" }),
]));
});
});