Created
March 26, 2019 11:48
-
-
Save fernandes/707c8c43827082ee558a8958f034a6a6 to your computer and use it in GitHub Desktop.
AVA + mock-fs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import test from 'ava' | |
import fs from 'fs' | |
import mock from 'mock-fs' | |
test.before(t => { | |
mock({ | |
'dir': { | |
'document': 'mocked content' | |
} | |
}) | |
}); | |
test.after.always(t => { | |
mock.restore() | |
}); | |
test('fs sync', t => { | |
var contents = fs.readFileSync('dir/document', 'utf8') | |
t.is(contents, 'mocked content', 'mocked file content') | |
}); | |
test('fs async', async t => { | |
const testReadFile = new Promise(function(resolve, reject) { | |
fs.readFile('dir/document', 'utf8', (err, data) => { | |
err ? reject(err) : resolve(data); | |
}) | |
}) | |
t.is(await testReadFile, 'mocked content', 'mocked file content') | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment