AVAの話 #mentaicojs

102 views

Published on

Talk about AVA, which is JavaScript test runner at mentaico.js #1.
http://mentaico-js.connpass.com/event/39906/

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
102
On SlideShare
0
From Embeds
0
Number of Embeds
7
Actions
Shares
0
Downloads
0
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

AVAの話 #mentaicojs

  1. 1. import test from 'ava'; test(t => { t.deepEqual([1, 2], [1, 2]); });
  2. 2. const delayHello = (msec, callback) => setTimeout(() => callback('Hello!'), msec); // t.endが呼ばれるまでテストを停止しない test.cb(t => { delayHello(1000, message => { t.is(message, 'Hello!'); t.end(); }); });
  3. 3. test(t => { // resolveするのを待ってくれる return somePromise().then(result => { t.is(result, 'unicorn'); }); });
  4. 4. function* generatorFun() { // 実際はファイル操作やAPIリクエストなど const a = yield Promise.resolve('a'); const b = yield Promise.resolve('b'); return `${a}:${b}`; } test(function* (t) { const message = yield generatorFun(); t.is(message, 'a:b'); });
  5. 5. import test from 'ava'; const promiseFun = () => Promise.resolve('Hello!'); test(async t => { const message = await promiseFun(); t.is(message, 'Hello!'); });
  6. 6. import test from 'ava'; // npm i rx@5.0.0-bata12 // ECMAScript Observableの実装 // https://github.com/tc39/proposal-observable import { Observable } from 'rxjs'; // test.cbは必要なし test(t => { t.plan(3); return Observable.of(1, 2, 3, 4, 5, 6) .filter(n => (n % 2 === 0)) // 2の倍数 .map(() => t.pass()); });
  7. 7.
  8. 8. const maybeThrowError = () => Promise.reject(new Error('Hello, error!!')); test(t => { return maybeThrowError().catch(err => { t.is(err.message, 'Hello, error!!'); }); });
  9. 9. // 意図せずPromiseがfullfillしてる const maybeThrowError = () => Promise.resolve('Invalid fullfilled'); // Promise.reject(new Error('...')); test(t => { return maybeThrowError().catch(err => { // そもそもここに入らないので、 // パスしちゃう...orz t.is(err.message, 'Hello, error!!'); }); });
  10. 10. test(t => { // 毎度両ケース書くのは複雑 return maybeThrowError() .then(() => t.fail()) .catch(err => { t.is(err.message, 'Hello, error!!'); }) }); });
  11. 11. test(t => { t.plan(1); return maybeThrowError().catch(err => { // ここを通らないと、 // assertionの回数が合わないので落ちる t.is(err.message, 'Hello, error!!'); }); });
  12. 12. 🍣 🍣 🍣
  13. 13. 🍣 🍣 🍣 🍣 🍣 🍣 🍣 🍣 🍣 🍣 🍣 🍣 🍣 🍣 🍣 🍣 🍣 🍣
  14. 14. 
 "
  15. 15. 
 

  16. 16. 🍣 🍣

×