灏天阁

Node/Koa2[53]: 个人主页-单元测试

· Yin灏

准备单元测试的数据

test/testUserInfo.js

module.exports = {
  USER_NAME: "zhangsan",
  COOKIE: "xxxx",
};

单元测试逻辑

test/blog/profile.test.js

const server = require("../server");
const { USER_NAME, COOKIE } = require("../testUserInfo");

test("个人主页,加载第一页数据应该成功", async () => {
  const res = await server
    .get(`/api/profile/loadMore/${USER_NAME}/0`)
    .set("cookie", COOKIE);
  expect(res.body.errno).toBe(0);
  const data = res.body.data;
  expect(data).toHaveProperty("isEmpty");
  expect(data).toHaveProperty("blogList");
  expect(data).toHaveProperty("pageSize");
  expect(data).toHaveProperty("pageIndex");
  expect(data).toHaveProperty("count");
});

- Book Lists -