-
-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: mail.assert to allow mail classes that accepts constructor argum…
…ents Fixes: #95
- Loading branch information
1 parent
667c796
commit 7f142f7
Showing
3 changed files
with
55 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -191,6 +191,41 @@ test.group('Fake mailer | mails | send', (group) => { | |
return true | ||
}) | ||
}) | ||
|
||
test('assert using mail class that accepts constructor arguments', async ({ assert, expectTypeOf }) => { | ||
Check failure on line 195 in tests/unit/fake_mailer/mails.spec.ts GitHub Actions / linux (20.10.0)
|
||
const emitter = new Emitter<MailEvents>(app) | ||
const mailer = new FakeMailer('mailgun', emitter, {}) | ||
const { mails } = mailer | ||
|
||
class VerifyEmail<UserId extends number> extends BaseMail { | ||
from: string = '[email protected]' | ||
subject: string = 'Verify your email address' | ||
|
||
constructor(public userId: UserId) { | ||
super() | ||
} | ||
|
||
prepare() { | ||
this.message.to('[email protected]') | ||
} | ||
} | ||
|
||
const response = await mailer.send(new VerifyEmail(1)) | ||
assert.exists(response.messageId) | ||
assert.deepEqual(response.envelope, { from: '[email protected]', to: ['[email protected]'] }) | ||
|
||
mails.assertSent(VerifyEmail) | ||
mails.assertSent(VerifyEmail, (mail) => { | ||
expectTypeOf(mail).toMatchTypeOf<VerifyEmail<number>> | ||
return mail.message.hasTo('[email protected]') && mail.message.hasFrom('[email protected]') | ||
}) | ||
|
||
assert.throws(() => { | ||
return mails.assertSent(VerifyEmail, (mail) => { | ||
return mail.message.hasTo('[email protected]') | ||
}) | ||
}, 'Expected mail "VerifyEmail" was not sent') | ||
}) | ||
}) | ||
|
||
test.group('Fake mailer | mails | sendLater', (group) => { | ||
|