From 1f1047c451361762e312321af9a8902d5e895a5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcus=20P=C3=B6hls?= Date: Fri, 16 Jan 2026 15:12:49 +0100 Subject: [PATCH] =?UTF-8?q?return=20this=20in=20MailsCollection=E2=80=99s?= =?UTF-8?q?=20assert=20methods?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/fake_mailer.ts | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/src/fake_mailer.ts b/src/fake_mailer.ts index e545c05..c6cb782 100644 --- a/src/fake_mailer.ts +++ b/src/fake_mailer.ts @@ -80,6 +80,8 @@ class MailsCollection { message: `Expected mail "${mailConstructor.name}" was not sent`, }) } + + return this } /** @@ -102,19 +104,21 @@ class MailsCollection { message: `Unexpected mail "${mailConstructor.name}" was sent`, }) } + + return this } /** * Assert a total of expected number of mails were sent */ - assertSentCount(count: number): void + assertSentCount(count: number): this /** * Assert the mentioned mail was sent for expected number * of times */ - assertSentCount(mailConstructor: Constructor, count: number): void - assertSentCount(mailConstructor: Constructor | number, count?: number): void { + assertSentCount(mailConstructor: Constructor, count: number): this + assertSentCount(mailConstructor: Constructor | number, count?: number): this { if (typeof mailConstructor === 'number') { const actual = this.#sent.length const expected = mailConstructor @@ -128,7 +132,7 @@ class MailsCollection { expected, }) } - return + return this } const actual = this.sent((mail) => mail instanceof mailConstructor).length @@ -143,6 +147,8 @@ class MailsCollection { expected, }) } + + return this } /** @@ -156,6 +162,8 @@ class MailsCollection { actual: [this.#sent.map((mail) => mail.constructor.name)], }) } + + return this } /** @@ -178,6 +186,8 @@ class MailsCollection { message: `Expected mail "${mailConstructor.name}" was not queued`, }) } + + return this } /** @@ -200,19 +210,21 @@ class MailsCollection { message: `Unexpected mail "${mailConstructor.name}" was queued`, }) } + + return this } /** * Assert a total of expected number of mails were queued */ - assertQueuedCount(count: number): void + assertQueuedCount(count: number): this /** * Assert the mentioned mail was queued for expected number * of times */ - assertQueuedCount(mailConstructor: Constructor, count: number): void - assertQueuedCount(mailConstructor: Constructor | number, count?: number): void { + assertQueuedCount(mailConstructor: Constructor, count: number): this + assertQueuedCount(mailConstructor: Constructor | number, count?: number): this { if (typeof mailConstructor === 'number') { const actual = this.#queued.length const expected = mailConstructor @@ -226,7 +238,7 @@ class MailsCollection { expected, }) } - return + return this } const actual = this.queued((mail) => mail instanceof mailConstructor).length @@ -241,6 +253,8 @@ class MailsCollection { expected, }) } + + return this } /** @@ -254,6 +268,8 @@ class MailsCollection { actual: [this.#queued.map((mail) => mail.constructor.name)], }) } + + return this } }