Skip to content

Instantly share code, notes, and snippets.

@kei0425
Last active March 16, 2017 04:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kei0425/38b478bc7ddcb5a1fb5caeba78946628 to your computer and use it in GitHub Desktop.
Save kei0425/38b478bc7ddcb5a1fb5caeba78946628 to your computer and use it in GitHub Desktop.
mocha async/await テスト
const fs = require('fs');
const assert = require("assert");
const pReadFile = (path) => new Promise((resolve, reject) => fs.readFile(path, (err, files) => {
if (err) {
reject(err);
}
else {
resolve(files);
}
}));
describe("test", function () {
it('case1', async function () {
let files = await pReadFile('./test/await-test.js');
assert.ok(files.length > 0);
});
it('case2', async function () {
let files = await pReadFile('./test/nofile');
assert.ok(files.length > 0);
});
it('case3', async function () {
assert.throws(async function () {
let files = await pReadFile('./test/nofile');
assert.ok(files.length > 0);
},
Error);
});
it('case4', async function () {
let err = null;
try {
let files = await pReadFile('./test/nofile');
assert.ok(files.length > 0);
} catch (e) {
err = e;
}
assert.equal(err && err.code, 'ENOENT');
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment