test: add test for fs shim

This commit is contained in:
bcheidemann 2021-03-07 15:05:18 +00:00
parent d6b29226aa
commit 8b57d299f4
1 changed files with 44 additions and 0 deletions

View File

@ -0,0 +1,44 @@
'use strict';
const expect = require('chai').expect;
const utils = require('../../lib/test-utils');
const fs = utils.shimIndexedDB(() => require('../../../shims/fs').default);
describe.only('fs shim', () => {
it('should be defined', () => {
expect(fs).to.not.be.undefined;
});
it('should be an object', () => {
expect(typeof fs).to.equal('object');
});
it('should return a function when accessing fs.writeFile', () => {
expect(typeof fs.writeFile).to.equal('function');
});
it('should call callback when calling fs.writeFile', (done) => {
fs.writeFile('/test.txt', 'test', function(err) {
if(err) throw err;
done();
});
});
it('should return an object when accessing fs.promises', () => {
expect(typeof fs.promises).to.equal('object');
});
it('should return a function when accessing fs.promises.writeFile', () => {
expect(typeof fs.promises.writeFile).to.equal('function');
});
it('should return a promise which resolves when calling fs.promises.writeFile', (done) => {
const writeFilePromise = fs.promises.writeFile('/test2.txt', '');
expect(writeFilePromise instanceof Promise).to.equal(true);
writeFilePromise.then(() => {
done();
}).catch((err) => {
done(err);
});
});
});