Skip to content

Commit

Permalink
fix: tests
Browse files Browse the repository at this point in the history
Add mock `logger` instance to all tests that use context.
  • Loading branch information
AlexanderLukin committed Jan 19, 2025
1 parent af8411e commit 0bb160b
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 3 deletions.
17 changes: 16 additions & 1 deletion __tests__/handlers_alternative.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -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
Expand All @@ -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: {
Expand Down Expand Up @@ -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: {
Expand Down
27 changes: 25 additions & 2 deletions __tests__/handlers_default.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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" },

Expand All @@ -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: {},

Expand Down Expand Up @@ -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: {},

Expand Down Expand Up @@ -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: {},

Expand Down Expand Up @@ -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: {},
};
Expand Down

0 comments on commit 0bb160b

Please sign in to comment.