@universal-packages/mailing-jest
v1.1.5
Published
Jest matchers for Mailing
Downloads
646
Readme
Mailing Jest
Jest matchers for Mailing testing.
Install
npm install @universal-packages/mailing-jest
npm install @universal-packages/mailing
Setup
Add the following to your jest.config.js
or where you configure Jest:
module.exports = {
setupFilesAfterEnv: ['@universal-packages/mailing-jest']
}
Matchers
toHaveSentTotal
import { Mailing } from '@universal-packages/mailing'
it('should send a given number of emails', async () => {
const mailer = new Mailing({ templatesLocation: './tests/__fixtures__' })
await mailer.prepare()
await mailer.send({ subject: 'Welcome', template: 'welcome-email', locals: { local: '123' } })
expect(Mailing).toHaveSentTotal(1)
})
toHaveSentOneWithOptions
import { Mailing } from '@universal-packages/mailing'
it('should send an email using the given options', async () => {
const mailer = new Mailing({ templatesLocation: './tests/__fixtures__' })
await mailer.prepare()
await mailer.send({ subject: 'Welcome', template: 'welcome-email', locals: { local: '123' } })
expect(Mailing).toHaveSentOneWithOptions({
subject: 'Welcome',
template: 'tests/__fixtures__/welcome-email',
locals: { local: '123' }
})
})
Typescript
In order for typescript to see the global types you need to reference the types somewhere in your project, normally ./src/globals.d.ts
.
/// <reference types="@universal-packages/mailing-jest" />
This library is developed in TypeScript and shipped fully typed.
Contributing
The development of this library happens in the open on GitHub, and we are grateful to the community for contributing bugfixes and improvements. Read below to learn how you can take part in improving this library.