Last active
March 16, 2017 04:53
-
-
Save kei0425/38b478bc7ddcb5a1fb5caeba78946628 to your computer and use it in GitHub Desktop.
mocha async/await テスト
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
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