1.0.7 • Published 29 days ago

@universal-packages/storage-jest v1.0.7

Weekly downloads
-
License
MIT
Repository
github
Last release
29 days ago

Storage Jest

npm version Testing codecov

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.

License

MIT licensed.

1.0.7

29 days ago

1.0.6

2 months ago

1.0.5

2 months ago

1.0.4

2 months ago

1.0.2

4 months ago

1.0.3

4 months ago

1.0.1

4 months ago

1.0.0

6 months ago