[**Documentation**](../../../README)

***

[Documentation](../../../README) / [@zerotal/notifications](../README) / NotificationFake

# Class: NotificationFake

Defined in: [notifications/src/NotificationFake.ts:34](https://github.com/zerotaldev/zerotal/blob/1d6fb26b05b18ba077de1bfaeb46c42131cd8b70/packages/notifications/src/NotificationFake.ts#L34)

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

## Example

```ts
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](https://github.com/zerotaldev/zerotal/blob/1d6fb26b05b18ba077de1bfaeb46c42131cd8b70/packages/notifications/src/NotificationFake.ts#L107)

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`](../interfaces/NotificationRecord)[]\>

###### Returns

`Promise`\<[`NotificationRecord`](../interfaces/NotificationRecord)[]\>

###### unread()

> **unread**(): `Promise`\<[`NotificationRecord`](../interfaces/NotificationRecord)[]\>

###### Returns

`Promise`\<[`NotificationRecord`](../interfaces/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](https://github.com/zerotaldev/zerotal/blob/1d6fb26b05b18ba077de1bfaeb46c42131cd8b70/packages/notifications/src/NotificationFake.ts#L45)

Replace the 'notifications' container binding with this fake.

#### Returns

`NotificationFake`

***

### restore()

> **restore**(): `void`

Defined in: [notifications/src/NotificationFake.ts:54](https://github.com/zerotaldev/zerotal/blob/1d6fb26b05b18ba077de1bfaeb46c42131cd8b70/packages/notifications/src/NotificationFake.ts#L54)

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

#### Returns

`void`

***

### send()

> **send**(`notifiable`, `notification`): `Promise`\<`void`\>

Defined in: [notifications/src/NotificationFake.ts:64](https://github.com/zerotaldev/zerotal/blob/1d6fb26b05b18ba077de1bfaeb46c42131cd8b70/packages/notifications/src/NotificationFake.ts#L64)

#### Parameters

##### notifiable

`Notifiable`

##### notification

[`Notification`](Notification)

#### Returns

`Promise`\<`void`\>

***

### queue()

> **queue**(`notifiable`, `notification`): `Promise`\<`void`\>

Defined in: [notifications/src/NotificationFake.ts:68](https://github.com/zerotaldev/zerotal/blob/1d6fb26b05b18ba077de1bfaeb46c42131cd8b70/packages/notifications/src/NotificationFake.ts#L68)

#### Parameters

##### notifiable

`Notifiable`

##### notification

[`Notification`](Notification)

#### Returns

`Promise`\<`void`\>

***

### sendMany()

> **sendMany**(`notifiables`, `notification`): `Promise`\<`void`\>

Defined in: [notifications/src/NotificationFake.ts:72](https://github.com/zerotaldev/zerotal/blob/1d6fb26b05b18ba077de1bfaeb46c42131cd8b70/packages/notifications/src/NotificationFake.ts#L72)

#### Parameters

##### notifiables

`Iterable`\<`Notifiable`\>

##### notification

[`Notification`](Notification)

#### Returns

`Promise`\<`void`\>

***

### queueMany()

> **queueMany**(`notifiables`, `notification`): `Promise`\<`void`\>

Defined in: [notifications/src/NotificationFake.ts:76](https://github.com/zerotaldev/zerotal/blob/1d6fb26b05b18ba077de1bfaeb46c42131cd8b70/packages/notifications/src/NotificationFake.ts#L76)

#### Parameters

##### notifiables

`Iterable`\<`Notifiable`\>

##### notification

[`Notification`](Notification)

#### Returns

`Promise`\<`void`\>

***

### route()

> **route**(`routes`): `object`

Defined in: [notifications/src/NotificationFake.ts:80](https://github.com/zerotaldev/zerotal/blob/1d6fb26b05b18ba077de1bfaeb46c42131cd8b70/packages/notifications/src/NotificationFake.ts#L80)

#### Parameters

##### routes

[`OnDemandRoutes`](../interfaces/OnDemandRoutes)

#### Returns

`object`

##### notify()

> **notify**(`notification`): `Promise`\<`void`\>

###### Parameters

###### notification

[`Notification`](Notification)

###### Returns

`Promise`\<`void`\>

##### notifyLater()

> **notifyLater**(`notification`): `Promise`\<`void`\>

###### Parameters

###### notification

[`Notification`](Notification)

###### Returns

`Promise`\<`void`\>

***

### extend()

> **extend**(): `this`

Defined in: [notifications/src/NotificationFake.ts:92](https://github.com/zerotaldev/zerotal/blob/1d6fb26b05b18ba077de1bfaeb46c42131cd8b70/packages/notifications/src/NotificationFake.ts#L92)

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](https://github.com/zerotaldev/zerotal/blob/1d6fb26b05b18ba077de1bfaeb46c42131cd8b70/packages/notifications/src/NotificationFake.ts#L96)

#### Returns

`string`[]

***

### sent()

> **sent**(): `CapturedNotification`[]

Defined in: [notifications/src/NotificationFake.ts:142](https://github.com/zerotaldev/zerotal/blob/1d6fb26b05b18ba077de1bfaeb46c42131cd8b70/packages/notifications/src/NotificationFake.ts#L142)

All captured notifications.

#### Returns

`CapturedNotification`[]

***

### sentTo()

> **sentTo**(`notifiable`): `CapturedNotification`[]

Defined in: [notifications/src/NotificationFake.ts:147](https://github.com/zerotaldev/zerotal/blob/1d6fb26b05b18ba077de1bfaeb46c42131cd8b70/packages/notifications/src/NotificationFake.ts#L147)

Captured notifications for one recipient.

#### Parameters

##### notifiable

`Notifiable`

#### Returns

`CapturedNotification`[]

***

### assertSentTo()

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

Defined in: [notifications/src/NotificationFake.ts:159](https://github.com/zerotaldev/zerotal/blob/1d6fb26b05b18ba077de1bfaeb46c42131cd8b70/packages/notifications/src/NotificationFake.ts#L159)

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`](Notification)

#### Parameters

##### notifiable

`Notifiable`

##### NotificationClass

(...`args`) => `T`

##### callback?

(`notification`) => `boolean`

#### Returns

`void`

#### Example

```ts
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](https://github.com/zerotaldev/zerotal/blob/1d6fb26b05b18ba077de1bfaeb46c42131cd8b70/packages/notifications/src/NotificationFake.ts#L174)

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

#### Type Parameters

##### T

`T` *extends* [`Notification`](Notification)

#### Parameters

##### notifiable

`Notifiable`

##### NotificationClass

(...`args`) => `T`

#### Returns

`void`

***

### assertSentOn()

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

Defined in: [notifications/src/NotificationFake.ts:192](https://github.com/zerotaldev/zerotal/blob/1d6fb26b05b18ba077de1bfaeb46c42131cd8b70/packages/notifications/src/NotificationFake.ts#L192)

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

#### Type Parameters

##### T

`T` *extends* [`Notification`](Notification)

#### Parameters

##### notifiable

`Notifiable`

##### NotificationClass

(...`args`) => `T`

##### channel

`string`

#### Returns

`void`

#### Example

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

***

### assertQueued()

> **assertQueued**\<`T`\>(`notifiable`, `NotificationClass`): `void`

Defined in: [notifications/src/NotificationFake.ts:213](https://github.com/zerotaldev/zerotal/blob/1d6fb26b05b18ba077de1bfaeb46c42131cd8b70/packages/notifications/src/NotificationFake.ts#L213)

Assert a notification was queued rather than sent immediately.

#### Type Parameters

##### T

`T` *extends* [`Notification`](Notification)

#### Parameters

##### notifiable

`Notifiable`

##### NotificationClass

(...`args`) => `T`

#### Returns

`void`

***

### assertSentTimes()

> **assertSentTimes**\<`T`\>(`NotificationClass`, `count`): `void`

Defined in: [notifications/src/NotificationFake.ts:227](https://github.com/zerotaldev/zerotal/blob/1d6fb26b05b18ba077de1bfaeb46c42131cd8b70/packages/notifications/src/NotificationFake.ts#L227)

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

#### Type Parameters

##### T

`T` *extends* [`Notification`](Notification)

#### Parameters

##### NotificationClass

(...`args`) => `T`

##### count

`number`

#### Returns

`void`

***

### assertNothingSent()

> **assertNothingSent**(): `void`

Defined in: [notifications/src/NotificationFake.ts:242](https://github.com/zerotaldev/zerotal/blob/1d6fb26b05b18ba077de1bfaeb46c42131cd8b70/packages/notifications/src/NotificationFake.ts#L242)

Assert that zero notifications were sent.

#### Returns

`void`

***

### assertSentCount()

> **assertSentCount**(`count`): `void`

Defined in: [notifications/src/NotificationFake.ts:252](https://github.com/zerotaldev/zerotal/blob/1d6fb26b05b18ba077de1bfaeb46c42131cd8b70/packages/notifications/src/NotificationFake.ts#L252)

Assert the exact total number of notifications sent.

#### Parameters

##### count

`number`

#### Returns

`void`
