本文整理汇总了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')
})
})
})
}
示例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()
});
示例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()
});
示例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();
});
示例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()
})
示例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();
});
});
示例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);
示例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);
});
});
示例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(() => {