Skip to content

Commit

Permalink
Use explicit true/false tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JstnMcBrd committed Oct 28, 2023
1 parent 3cd9bb5 commit ec4a40a
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 24 deletions.
6 changes: 3 additions & 3 deletions src/commandContext/followUp.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ describe('follow-up message', () => {
test('logs an error if the follow-up fails', async () => {
const testError = new Error('This is a test');
mockInteractionFollowUp.mockRejectedValueOnce(testError);
await expect(followUp('yo')).resolves.toBeFalsy();
await expect(followUp('yo')).resolves.toBe(false);
expect(mockSendMessageInChannel).not.toHaveBeenCalled();
expect(mockLoggerError).toHaveBeenCalledOnce();
expect(mockLoggerError).toHaveBeenCalledWith(expect.stringContaining('follow up'), testError);
Expand All @@ -62,7 +62,7 @@ describe('follow-up message', () => {
test('logs an error if the follow-up with options fails', async () => {
const testError = new Error('This is a test');
mockInteractionFollowUp.mockRejectedValueOnce(testError);
await expect(followUp({ content: 'yo' })).resolves.toBeFalsy();
await expect(followUp({ content: 'yo' })).resolves.toBe(false);
expect(mockSendMessageInChannel).not.toHaveBeenCalled();
expect(mockLoggerError).toHaveBeenCalledOnce();
expect(mockLoggerError).toHaveBeenCalledWith(expect.stringContaining('follow up'), testError);
Expand All @@ -88,7 +88,7 @@ describe('follow-up message', () => {

test('returns false if the plain message fallback failed', async () => {
mockSendMessageInChannel.mockResolvedValueOnce(null);
await expect(followUp({ content: 'yo', reply: false })).resolves.toBeFalsy();
await expect(followUp({ content: 'yo', reply: false })).resolves.toBe(false);
expect(mockLoggerError).not.toHaveBeenCalled();
expect(mockInteractionFollowUp).not.toHaveBeenCalled();
expect(mockSendMessageInChannel).toHaveBeenCalledOnce();
Expand Down
24 changes: 13 additions & 11 deletions src/helpers/actions/messages/replyToMessage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,30 +37,30 @@ describe('Replies', () => {

test('sends an ephemeral reply with text', async () => {
const content = 'yo';
await expect(replyWithPrivateMessage(interaction, content, false)).resolves.toBeTruthy();
await expect(replyWithPrivateMessage(interaction, content, false)).resolves.toBe(true);
expect(mockReply).toHaveBeenCalledOnce();
expect(mockReply).toHaveBeenCalledWith({ content, ephemeral: true });
});

test('returns false when an ephemeral reply with text fails', async () => {
mockReply.mockRejectedValueOnce(new Error('This is a test'));
const content = 'yo';
await expect(replyWithPrivateMessage(interaction, content, false)).resolves.toBeFalsy();
await expect(replyWithPrivateMessage(interaction, content, false)).resolves.toBe(false);
expect(mockReply).toHaveBeenCalledOnce();
expect(mockReply).toHaveBeenCalledWith({ content, ephemeral: true });
});

test('sends an ephemeral reply with options', async () => {
const content = 'yo';
await expect(replyWithPrivateMessage(interaction, { content }, false)).resolves.toBeTruthy();
await expect(replyWithPrivateMessage(interaction, { content }, false)).resolves.toBe(true);
expect(mockReply).toHaveBeenCalledOnce();
expect(mockReply).toHaveBeenCalledWith({ content, ephemeral: true });
});

test('returns false when an ephemeral reply with options fails', async () => {
mockReply.mockRejectedValueOnce(new Error('This is a test'));
const content = 'yo';
await expect(replyWithPrivateMessage(interaction, { content }, false)).resolves.toBeFalsy();
await expect(replyWithPrivateMessage(interaction, { content }, false)).resolves.toBe(false);
expect(mockReply).toHaveBeenCalledOnce();
expect(mockReply).toHaveBeenCalledWith({ content, ephemeral: true });
});
Expand Down Expand Up @@ -93,7 +93,7 @@ describe('Replies', () => {
mockUserSend.mockRejectedValueOnce(error);

const content = 'yo';
await expect(replyWithPrivateMessage(interaction, content, true)).resolves.toBeTruthy();
await expect(replyWithPrivateMessage(interaction, content, true)).resolves.toBe(true);
expect(mockUserSend).toHaveBeenCalledOnce();
expect(mockUserSend).toHaveBeenCalledWith(`(Reply from <#channel-1234>)\n${content}`);
expect(mockReply).toHaveBeenCalledOnce();
Expand All @@ -112,7 +112,7 @@ describe('Replies', () => {
mockUserSend.mockRejectedValueOnce(error);

const options = { content: 'yo' };
await expect(replyWithPrivateMessage(interaction, options, true)).resolves.toBeTruthy();
await expect(replyWithPrivateMessage(interaction, options, true)).resolves.toBe(true);
expect(mockUserSend).toHaveBeenCalledOnce();
expect(mockUserSend).toHaveBeenCalledWith({
content: `(Reply from <#channel-1234>)\n${options.content}`,
Expand Down Expand Up @@ -156,7 +156,7 @@ describe('Replies', () => {

test('sends a DM with a return prefix from text', async () => {
const content = 'yo';
await expect(replyWithPrivateMessage(message, content, true)).resolves.toBeTruthy();
await expect(replyWithPrivateMessage(message, content, true)).resolves.toBeTypeOf('object');
expect(mockReply).not.toHaveBeenCalled();
expect(mockChannelSend).not.toHaveBeenCalled();
expect(mockUserSend).toHaveBeenCalledOnce();
Expand All @@ -168,7 +168,7 @@ describe('Replies', () => {
test('sends a DM with a return prefix from missing text', async () => {
await expect(
replyWithPrivateMessage(message, { content: undefined }, true)
).resolves.toBeTruthy();
).resolves.toBeTypeOf('object');
expect(mockReply).not.toHaveBeenCalled();
expect(mockChannelSend).not.toHaveBeenCalled();
expect(mockUserSend).toHaveBeenCalledOnce();
Expand All @@ -179,7 +179,9 @@ describe('Replies', () => {

test('sends a DM with a return prefix from options', async () => {
const content = 'yo';
await expect(replyWithPrivateMessage(message, { content }, true)).resolves.toBeTruthy();
await expect(replyWithPrivateMessage(message, { content }, true)).resolves.toBeTypeOf(
'object'
);
expect(mockReply).not.toHaveBeenCalled();
expect(mockChannelSend).not.toHaveBeenCalled();
expect(mockUserSend).toHaveBeenCalledOnce();
Expand All @@ -191,7 +193,7 @@ describe('Replies', () => {
test('informs the user when DMs failed', async () => {
mockUserSend.mockRejectedValueOnce(new Error('This is a test'));
const content = 'yo';
await expect(replyWithPrivateMessage(message, content, true)).resolves.toBeFalsy();
await expect(replyWithPrivateMessage(message, content, true)).resolves.toBe(false);
expect(mockUserSend).toHaveBeenCalledOnce();
expect(mockUserSend).toHaveBeenCalledWith(
`(Reply from <#${message.channel.id}>)\n${content}`
Expand All @@ -211,7 +213,7 @@ describe('Replies', () => {
mockReply.mockRejectedValueOnce(error);

const content = 'yo';
await expect(replyWithPrivateMessage(message, content, true)).resolves.toBeFalsy();
await expect(replyWithPrivateMessage(message, content, true)).resolves.toBe(false);
expect(mockUserSend).toHaveBeenCalledOnce();
expect(mockUserSend).toHaveBeenCalledWith(
`(Reply from <#${message.channel.id}>)\n${content}`
Expand Down
16 changes: 8 additions & 8 deletions src/helpers/guards/isError.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@ class TestNonError {

describe('isError', () => {
test('returns true for Error instances', () => {
expect(isError(new Error('This is an error'))).toBeTruthy();
expect(isError(new Error('This is an error'))).toBe(true);
});

test('returns true for Error subclasses', () => {
expect(isError(new EvalError('This is an error'))).toBeTruthy();
expect(isError(new RangeError('This is an error'))).toBeTruthy();
expect(isError(new ReferenceError('This is an error'))).toBeTruthy();
expect(isError(new SyntaxError('This is an error'))).toBeTruthy();
expect(isError(new TestError())).toBeTruthy();
expect(isError(new TypeError('This is an error'))).toBeTruthy();
expect(isError(new EvalError('This is an error'))).toBe(true);
expect(isError(new RangeError('This is an error'))).toBe(true);
expect(isError(new ReferenceError('This is an error'))).toBe(true);
expect(isError(new SyntaxError('This is an error'))).toBe(true);
expect(isError(new TestError())).toBe(true);
expect(isError(new TypeError('This is an error'))).toBe(true);
});

test.each`
Expand All @@ -42,6 +42,6 @@ describe('isError', () => {
${{ key: 'value' }}
${new TestNonError()}
`('returns false for non-error value: $value', ({ value }: { value: unknown }) => {
expect(isError(value)).toBeFalsy();
expect(isError(value)).toBe(false);
});
});
4 changes: 2 additions & 2 deletions src/helpers/guards/isNonEmptyArray.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { isNonEmptyArray } from './isNonEmptyArray';

describe('Nonempty array', () => {
test('returns false for an empty array', () => {
expect(isNonEmptyArray([])).toBeFalsy();
expect(isNonEmptyArray([])).toBe(false);
});

test.each`
Expand All @@ -16,6 +16,6 @@ describe('Nonempty array', () => {
`('returns true for an array of $length item(s)', ({ length }: { length: number }) => {
const array = new Array<number>(length).fill(8);
expect(array.length).toBe(length); // sanity check
expect(isNonEmptyArray(array)).toBeTruthy();
expect(isNonEmptyArray(array)).toBe(true);
});
});

0 comments on commit ec4a40a

Please sign in to comment.