Skip to main content
zerotal

Documentation


Documentation / @zerotal/notifications / NotificationFake

Class: NotificationFake

Defined in: notifications/src/NotificationFake.ts:34

Drop-in replacement for NotificationManager that captures sent notifications instead of delivering them. Install at the start of a test; restore after.

Example

const notify = NotificationFake.install();

await Notify.send(user, new OrderShippedNotification(order));

notify.assertSentTo(user, OrderShippedNotification);
notify.assertSentOn(user, OrderShippedNotification, "mail");
notify.assertNothingSent(); // or assertSentCount(1)

notify.restore(); // call in afterEach

Accessors

database

Get Signature

get database(): object

Defined in: notifications/src/NotificationFake.ts:107

An inert stand-in for the real database channel.

A faked send writes no rows, so the inbox is empty rather than absent — code under test that reads unreadNotifications() keeps working instead of throwing on a missing property. Assert on what was sent, not on this.

Returns

object

all()

all(): Promise<NotificationRecord[]>

Returns

Promise<NotificationRecord[]>

unread()

unread(): Promise<NotificationRecord[]>

Returns

Promise<NotificationRecord[]>

unreadCount()

unreadCount(): Promise<number>

Returns

Promise<number>

markAllAsRead()

markAllAsRead(): Promise<void>

Returns

Promise<void>

markAsRead()

markAsRead(): Promise<void>

Returns

Promise<void>

markAsUnread()

markAsUnread(): Promise<void>

Returns

Promise<void>

delete()

delete(): Promise<void>

Returns

Promise<void>

clear()

clear(): Promise<void>

Returns

Promise<void>

Methods

install()

static install(): NotificationFake

Defined in: notifications/src/NotificationFake.ts:45

Replace the 'notifications' container binding with this fake.

Returns

NotificationFake


restore()

restore(): void

Defined in: notifications/src/NotificationFake.ts:54

Restore the original 'notifications' binding. Call in afterEach.

Returns

void


send()

send(notifiable, notification): Promise<void>

Defined in: notifications/src/NotificationFake.ts:64

Parameters

notifiable

Notifiable

notification

Notification

Returns

Promise<void>


queue()

queue(notifiable, notification): Promise<void>

Defined in: notifications/src/NotificationFake.ts:68

Parameters

notifiable

Notifiable

notification

Notification

Returns

Promise<void>


sendMany()

sendMany(notifiables, notification): Promise<void>

Defined in: notifications/src/NotificationFake.ts:72

Parameters

notifiables

Iterable<Notifiable>

notification

Notification

Returns

Promise<void>


queueMany()

queueMany(notifiables, notification): Promise<void>

Defined in: notifications/src/NotificationFake.ts:76

Parameters

notifiables

Iterable<Notifiable>

notification

Notification

Returns

Promise<void>


route()

route(routes): object

Defined in: notifications/src/NotificationFake.ts:80

Parameters

routes

OnDemandRoutes

Returns

object

notify()

notify(notification): Promise<void>

Parameters
notification

Notification

Returns

Promise<void>

notifyLater()

notifyLater(notification): Promise<void>

Parameters
notification

Notification

Returns

Promise<void>


extend()

extend(): this

Defined in: notifications/src/NotificationFake.ts:92

Registering a custom channel on the fake is a no-op — nothing is delivered.

Returns

this


channels()

channels(): string[]

Defined in: notifications/src/NotificationFake.ts:96

Returns

string[]


sent()

sent(): CapturedNotification[]

Defined in: notifications/src/NotificationFake.ts:142

All captured notifications.

Returns

CapturedNotification[]


sentTo()

sentTo(notifiable): CapturedNotification[]

Defined in: notifications/src/NotificationFake.ts:147

Captured notifications for one recipient.

Parameters

notifiable

Notifiable

Returns

CapturedNotification[]


assertSentTo()

assertSentTo<T>(notifiable, NotificationClass, callback?): void

Defined in: notifications/src/NotificationFake.ts:159

Assert that a notification was sent to the given notifiable. Pass an optional filter callback to narrow the assertion.

Type Parameters

T

T extends Notification

Parameters

notifiable

Notifiable

NotificationClass

(...args) => T

callback?

(notification) => boolean

Returns

void

Example

notify.assertSentTo(user, OrderShippedNotification);
notify.assertSentTo(user, OrderShippedNotification, (n) => n.orderId === 42);

assertNotSentTo()

assertNotSentTo<T>(notifiable, NotificationClass): void

Defined in: notifications/src/NotificationFake.ts:174

Assert that a notification class was NOT sent to the given notifiable.

Type Parameters

T

T extends Notification

Parameters

notifiable

Notifiable

NotificationClass

(...args) => T

Returns

void


assertSentOn()

assertSentOn<T>(notifiable, NotificationClass, channel): void

Defined in: notifications/src/NotificationFake.ts:192

Assert a notification was sent to a recipient on a specific channel.

Type Parameters

T

T extends Notification

Parameters

notifiable

Notifiable

NotificationClass

(...args) => T

channel

string

Returns

void

Example

notify.assertSentOn(user, PasswordChanged, "mail");

assertQueued()

assertQueued<T>(notifiable, NotificationClass): void

Defined in: notifications/src/NotificationFake.ts:213

Assert a notification was queued rather than sent immediately.

Type Parameters

T

T extends Notification

Parameters

notifiable

Notifiable

NotificationClass

(...args) => T

Returns

void


assertSentTimes()

assertSentTimes<T>(NotificationClass, count): void

Defined in: notifications/src/NotificationFake.ts:227

Assert how many times a notification class was sent, to anyone.

Type Parameters

T

T extends Notification

Parameters

NotificationClass

(...args) => T

count

number

Returns

void


assertNothingSent()

assertNothingSent(): void

Defined in: notifications/src/NotificationFake.ts:242

Assert that zero notifications were sent.

Returns

void


assertSentCount()

assertSentCount(count): void

Defined in: notifications/src/NotificationFake.ts:252

Assert the exact total number of notifications sent.

Parameters

count

number

Returns

void