当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript ava.cb函数代码示例

本文整理汇总了TypeScript中ava.cb函数的典型用法代码示例。如果您正苦于以下问题:TypeScript cb函数的具体用法?TypeScript cb怎么用?TypeScript cb使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了cb函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: startTest

 startTest(testName: string, callback: (t: ActionsOnGoogleAva) => Promise<AssistResponse>) {
     this._isNewConversation = true
     test.cb(testName, t => {
         this._t = t
         this._t.plan(1)
         console.log(`** Starting test ${testName} **`)
         callback(this)
             .then(() => {
                 // The test has completed successfully
                 // If the test exits early, only the
                 // `finally` function will be run
                 console.log('test passes')
                 this._t.pass()
             })
             .catch((e: Error) => {
                 console.log('test error', e)
             })
             .finally(() => {
                 return this.endConversation()
                     .then((res) => {
                         console.log('test ends')
                         this._t.end()
                         console.log('\n')
                     })
             })
     })
 }
开发者ID:manoj253,项目名称:actions-on-google-testing-nodejs,代码行数:27,代码来源:actions-on-google-ava.ts

示例2:

import test from 'ava';
import knapsack from './p2';

test.cb((t) => {
  t.is(knapsack(50, [{value: 60, weight: 20}, {value: 100, weight: 50}, {value: 120, weight: 30}]), 180);
  t.end()
});

test.cb((t) => {
  t.is(knapsack(10, [{value: 500, weight: 30}]), 166.6667);
  t.end()
});
开发者ID:infernalmaster,项目名称:coursera-algorithmic-toolbox,代码行数:12,代码来源:p2.test.ts

示例3:

import test from 'ava';
import moneyChange from './p1';

test.cb((t) => {
  t.is(moneyChange(2), 2);
  t.end()
});

test.cb((t) => {
  t.is(moneyChange(28), 6);
  t.end()
});


test.cb((t) => {
  t.is(moneyChange(12324), 1236);
  t.end()
});
开发者ID:infernalmaster,项目名称:coursera-algorithmic-toolbox,代码行数:18,代码来源:p1.test.ts

示例4:

import test from 'ava';
import fibReminder, {calculateSequences} from './fibReminder';

test.only.cb((t) => {
  t.is(fibReminder(5, 2), 1);
  t.is(fibReminder(4, 2), 1);
  t.is(fibReminder(11, 3), 2);
  t.is(fibReminder(10, 3), 1);
  t.is(fibReminder(281621358815590, 30524), 11963);
  t.end()
});


test.cb('calculdateSequences', (t) => {
  t.deepEqual(calculateSequences(2), [0, 1, 1]);
  t.deepEqual(calculateSequences(3), [0, 1, 1, 2, 0, 2, 2, 1]);
  t.deepEqual(calculateSequences(4), [0, 1, 1, 2, 3, 1]);
  t.deepEqual(calculateSequences(5), [0, 1, 1, 2, 3, 0, 3, 3, 1, 4, 0, 4, 4, 3, 2, 0, 2, 2, 4, 1]);

  // t.is(calculateSequences(30524), [0]);

  t.end();
});
开发者ID:infernalmaster,项目名称:coursera-algorithmic-toolbox,代码行数:23,代码来源:fibReminder.test.ts

示例5: quickSort

import test from 'ava'
import {quickSort, quickSortAdvanced} from './p3'

test.cb(t => {
  const arr = [2, 3, 9, 2, 2]
  quickSort(arr)
  t.deepEqual(arr, [2, 2, 2, 3, 9])
  t.end()
})

test.cb(t => {
  const arr = [2, 3, 9, 2, 2]
  quickSortAdvanced(arr)
  t.deepEqual(arr, [2, 2, 2, 3, 9])
  t.end()
})

开发者ID:infernalmaster,项目名称:coursera-algorithmic-toolbox,代码行数:16,代码来源:p3.test.ts

示例6: runClient

/**
 * Test createRxServer
 * Run with `npm test`
 */
import * as rxs from "./rxserver";
import test from "ava";
import * as net from "net";

function runClient() {
  let client = net.connect({port: 1234}, () => {
    client.write(Buffer.from("hello"));
    client.end();
  });
}
setTimeout(runClient, 300);

/** test createRxServer() */
test.cb(function testRxServer(t) {
  t.plan(1);
  rxs.createRxServer({port: 1234})
    .mergeAll()
    .pluck("buffer")
    .map(b => b.toString())
    .subscribe(str => {
      t.is(str, "hello");
      t.end();
    });
});
开发者ID:dancasey,项目名称:node-rx-server,代码行数:28,代码来源:test.ts

示例7: test

test('objectParamsToParams can flatten an object', function(t) {
    t.deepEqual(
        objectParamsToParams(['a', 'b'], {a: 1, b: 2}),
        [1, 2]
    );
});

test.cb('makeAsyncAutoTaskSpec returns function for async.auto', (t) => {
    let ar = makeAsyncAutoTaskSpec(
        ['a', 'b'],
        function readFiles(aFile, bFile, next) {
            t.is(aFile, 'x');
            t.is(bFile, 'y');
            next(1, 2);
        }
    );
    t.is(ar[0], 'a');
    t.is(ar[1], 'b');
    let func = ar[2];
    func({ a: 'x', b: 'y'}, function(a, b) {
        t.is(a, 1);
        t.is(b, 2);
        t.end();
    });
});

test.cb('promiseToCallback converts a promise returner to callback', (t) => {

    function promiseFunc(a: number, b: number) {
        return new Promise(function(resolve) {
            setTimeout(function() {
                resolve(a + b);
开发者ID:forbesmyester,项目名称:async-auto-funcs,代码行数:32,代码来源:index.ts

示例8: Pasteurize

  t.throws(() => { var pasteurize = new Pasteurize(64, 256, null, 'sha512'); }, TypeError);
  t.throws(() => { var pasteurize = new Pasteurize(64, 256, -1, 'sha512'); }, TypeError);
});

test('Errors if digest bad', (t) => {
  t.plan(2);

  t.throws(() => { var pasteurize = new Pasteurize(64, 256, 100, null); }, TypeError);
  t.throws(() => { var pasteurize = new Pasteurize(64, 256, 100, 'obviously bad digest'); }, TypeError);
});

test.cb('Async verify good password', (t) => {
  t.plan(2);
  var pasteurize = new Pasteurize(64, 256, 100, 'sha512');

  pasteurize.verifyPassword('password1', internals.hashes.password1, (err: Error, verified: boolean) => {
    t.ifError(err);
    t.truthy(verified);
    t.end();
  });
});

test('Async verify returns promise', (t) => {
  t.plan(1);
  var pasteurize = new Pasteurize(64, 256, 100, 'sha512');

  return pasteurize.verifyPassword('password1', internals.hashes.password1)
  .then((verified) => {
    t.truthy(verified);
  });
});
开发者ID:zefferus,项目名称:pasteurize,代码行数:31,代码来源:pasteurize.test.ts

示例9: test

        res.end();
    });

    await s.listen(s.port);
});

test('option.json can not be used', (t) => {
    t.throws(() => {
        got.stream(s.url, {json: true});
    }, 'got can not be used as stream when options.json is used');
});

test.cb('returns readable stream', (t) => {
    got.stream(s.url)
        .on('data', data => {
            t.is(data.toString(), 'ok');
            t.end();
        });
});

test.cb('returns writeable stream', (t) => {
    got.stream.post(`${s.url}/post`)
        .on('data', data => {
            t.is(data.toString(), 'wow');
            t.end();
        })
        .end('wow');
});

test.cb('throws on writet o stream with body specified', (t) => {
    t.throws(() => {
开发者ID:cyounkins,项目名称:typed-got,代码行数:31,代码来源:stream.ts


注:本文中的ava.cb函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。