0.2.0 • Published 4 years ago

@mock/fs v0.2.0

Weekly downloads
1
License
MIT
Repository
github
Last release
4 years ago

@mock/fs npm

Mock FS in-memory using memfs.

Install

$ yarn add --dev @mock/fs

Usage

const mockFs: (file: string) => () => void
// get-data.js
import { promises } from 'fs'

export const getData = (): Promise<string> => promises.readFile('./data.txt', 'utf8')
import test from 'blue-tape'
import { mockFs } from '@mock/fs'

test('getData', async (t) => {
  const { fs, unmockFs } = mockFs('./get-data')

  fs.writeFileSync('./data.txt', 'fake data')

  const { getData } = await import('./get-data')
  const data = await getData()

  t.equal(
    data,
    'fake data',
    'should get data'
  )

  unmockFs()
})