From 0bb160bdfb922d002aa4ee3f2801cda9f396528a Mon Sep 17 00:00:00 2001 From: Alexander Lukin Date: Sun, 19 Jan 2025 22:05:04 +0400 Subject: [PATCH] fix: tests Add mock `logger` instance to all tests that use context. --- __tests__/handlers_alternative.test.js | 17 +++++++++++++++- __tests__/handlers_default.test.js | 27 ++++++++++++++++++++++++-- 2 files changed, 41 insertions(+), 3 deletions(-) diff --git a/__tests__/handlers_alternative.test.js b/__tests__/handlers_alternative.test.js index 81e76e7..f7fcd4a 100644 --- a/__tests__/handlers_alternative.test.js +++ b/__tests__/handlers_alternative.test.js @@ -17,6 +17,11 @@ test("hook works", async () => { // mock const ctx = { routes: { test: "/dev/null" }, + logger: { + info: jest.fn(), + warn: jest.fn(), + error: jest.fn(), + }, params: { slug: "test" }, request: { body: { @@ -34,7 +39,7 @@ test("hook works", async () => { expect(axios.post.mock.calls).toMatchSnapshot(); }); -test("balval features is correct", async () => { +test("balval features are correct", async () => { const getAlert = (i) => { return { status: i % 2 === 0 ? "resolved" : "fired", // resolved should be first @@ -53,6 +58,11 @@ test("balval features is correct", async () => { // mock const ctx = { routes: { test: "/dev/null" }, + logger: { + info: jest.fn(), + warn: jest.fn(), + error: jest.fn(), + }, params: { slug: "test" }, request: { body: { @@ -87,6 +97,11 @@ test("mention works", async () => { // mock const ctx = { routes: { test: "/dev/null" }, + logger: { + info: jest.fn(), + warn: jest.fn(), + error: jest.fn(), + }, params: { slug: "test" }, request: { body: { diff --git a/__tests__/handlers_default.test.js b/__tests__/handlers_default.test.js index 63e4a1b..7b38e4a 100644 --- a/__tests__/handlers_default.test.js +++ b/__tests__/handlers_default.test.js @@ -18,6 +18,11 @@ test("hook works (no mentions)", async () => { // mock const ctx = { routes: { test: "/dev/null" }, + logger: { + info: jest.fn(), + warn: jest.fn(), + error: jest.fn(), + }, params: { slug: "test" }, query: { q: "42" }, @@ -41,6 +46,11 @@ test("hook works (missing annotations subfield)", async () => { // mock const ctx = { routes: { test: "/dev/null" }, + logger: { + info: jest.fn(), + warn: jest.fn(), + error: jest.fn(), + }, params: { slug: "test" }, query: {}, @@ -75,11 +85,15 @@ test("hook works (missing annotations subfield)", async () => { expect(axios.post.mock.calls).toMatchSnapshot(); }); - test("hook works (mentions)", async () => { // mock const ctx = { routes: { test: "/dev/null" }, + logger: { + info: jest.fn(), + warn: jest.fn(), + error: jest.fn(), + }, params: { slug: "test" }, query: {}, @@ -107,6 +121,11 @@ test("hook works (fields)", async () => { // mock const ctx = { routes: { test: "/dev/null" }, + logger: { + info: jest.fn(), + warn: jest.fn(), + error: jest.fn(), + }, params: { slug: "test" }, query: {}, @@ -134,11 +153,15 @@ test("hook works (fields)", async () => { expect(axios.post.mock.calls).toMatchSnapshot(); }); - test("healthcheck works", async () => { // mock const ctx = { routes: { test: "/dev/null" }, + logger: { + info: jest.fn(), + warn: jest.fn(), + error: jest.fn(), + }, params: { slug: "test" }, query: {}, };