@universal-packages/storage-jest
v1.0.11
Published
Jest matchers for Storage
Downloads
16
Readme
Storage Jest
Jest matchers for Storage testing.
Install
npm install @universal-packages/storage-jest
npm install @universal-packages/storage
Setup
Add the following to your jest.config.js
or where you configure Jest:
module.exports = {
setupFilesAfterEnv: ['@universal-packages/storage-jest']
}
Matchers
toHaveStored
import { Storage } from '@universal-packages/storage'
import config from './config'
it('should store file', async () => {
const storage = new Storage(config)
await storage.store({ name: 'file.png', data: buffer })
expect(storage).toHaveStored('./path/to/file.png')
// Or against the Storage class
expect(Storage).toHaveStored('./path/to/file.png')
})
toHaveStoredVersion
import { Storage } from '@universal-packages/storage'
import config from './config'
it('should store file', async () => {
const storage = new Storage(config)
const key = await storage.store({ name: 'file.png', data: buffer })
await storage.storeVersion(key, { width: 100, height: 100 })
expect(storage).toHaveStoredVersion('./path/to/file.png', { width: 100, height: 100 })
// Or against the Storage class
expect(Storage).toHaveStoredVersion('./path/to/file.png', { width: 100, height: 100 })
})
toHaveDisposed
import { Storage } from '@universal-packages/storage'
import config from './config'
it('should dispose file', async () => {
const storage = new Storage(config)
const key = await storage.store({ name: 'file.png', data: buffer })
await storage.dispose(key)
expect(storage).toHaveDisposed(key)
// Or against the Storage class
expect(Storage).toHaveDisposed(key)
})
toHaveDisposedVersion
import { Storage } from '@universal-packages/storage'
import config from './config'
it('should dispose file', async () => {
const storage = new Storage(config)
const key = await storage.store({ name: 'file.png', data: buffer })
await storage.storeVersion(key, { width: 100, height: 100 })
await storage.disposeVersion(key, { width: 100, height: 100 })
expect(storage).toHaveDisposedVersion(key, { width: 100, height: 100 })
// Or against the Storage class
expect(Storage).toHaveDisposedVersion(key, { width: 100, height: 100 })
})
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/storage-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.