本文整理汇总了TypeScript中ava.test.cb方法的典型用法代码示例。如果您正苦于以下问题:TypeScript test.cb方法的具体用法?TypeScript test.cb怎么用?TypeScript test.cb使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ava.test
的用法示例。
在下文中一共展示了test.cb方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: express
import { json } from 'body-parser';
import AppVeyorClient from '../lib/appveyor';
test.cb('appveyor > get', t => {
const expectedResponse = {data: 'something'};
const server = express();
server.get('/data', (req, res) => {
res.send(JSON.stringify(expectedResponse));
});
server.listen(3000, () => {
const appVeyorClient = new AppVeyorClient("my token");
appVeyorClient.hostname = 'localhost';
appVeyorClient.port = 3000;
appVeyorClient.protocol = 'http:';
appVeyorClient.get('/data')
.then(res => {
t.is(res.ok, true);
t.is(res.statusCode, 200);
t.deepEqual(res.body, expectedResponse);
t.end();
})
.catch(t.end);
});
});
test.cb('appveyor > post', t => {
const expectedRequest = {input: 'whatever'};
示例2: start
const TOO_SLOW_MS = 10000
test.serial("performs well on small scenario", t => {
t.true(smallScenario(10).elapsed < TOO_SLOW_MS)
})
test.serial("performs well on medium scenario", t => {
t.true(mediumScenario(10).elapsed < TOO_SLOW_MS)
})
test.serial("performs well on large scenario", t => {
t.true(largeScenario(10, 0, 0).elapsed < TOO_SLOW_MS)
t.true(largeScenario(10, 10, 0).elapsed < TOO_SLOW_MS)
t.true(largeScenario(10, 0, 10).elapsed < TOO_SLOW_MS)
t.true(largeScenario(10, 10, 10).elapsed < TOO_SLOW_MS)
})
test.cb("timer", t => {
const go = start()
setTimeout(function() {
const lap = go(true)
setTimeout(function() {
const done = go()
t.not(lap, 0)
t.not(done, 0)
t.not(lap, done)
t.end()
}, 2)
}, 2)
})
示例3: flow
)
}
test.cb("flow happens in single ticks", t => {
const X = types
.model({
y: 1
})
.actions(self => ({
p: flow(function*() {
self.y++
self.y++
yield delay(1, true, false)
self.y++
self.y++
})
}))
const x = X.create()
const values: number[] = []
reaction(() => x.y, v => values.push(v))
debugger
x.p().then(() => {
t.is(x.y, 5)
t.deepEqual(values, [3, 5])
t.end()
})
})
test.cb("can handle async actions", t => {
testCoffeeTodo(
示例4: Promise
test.cb("it should support dynamic loading", t => {
const events: string[] = []
const User = types.model({
name: types.string,
age: 0
})
const UserByNameReference = types.maybe(
types.reference(User, {
get(identifier /* string */, parent: any /*Store*/) {
return parent.getOrLoadUser(identifier)
},
set(value /* User */) {
return value.name
}
})
)
const Store = types
.model({
users: types.array(User),
selection: UserByNameReference
})
.actions(self => ({
loadUser: flow(function* loadUser(name) {
events.push("loading " + name)
self.users.push({ name } as any)
yield new Promise(resolve => {
setTimeout(resolve, 200)
})
events.push("loaded " + name)
const user = (self.users.find(u => u.name === name).age = name.length * 3) // wonderful!
})
}))
.views(self => ({
// Important: a view so that the reference will automatically react to the reference being changed!
getOrLoadUser(name) {
const user = self.users.find(u => u.name === name) || null
if (!user) {
/*
TODO: this is ugly, but workaround the idea that views should be side effect free.
We need a more elegant solution..
*/
setImmediate(() => self.loadUser(name))
}
return user
}
}))
const s = Store.create({
users: [],
selection: "Mattia"
})
unprotect(s)
t.deepEqual(events, [])
t.is(s.users.length, 0)
t.is(s.selection, null)
when(
() => s.users.length === 1 && s.users[0].age === 18 && s.users[0].name === "Mattia",
() => {
t.is(s.selection, s.users[0])
t.deepEqual(events, ["loading Mattia", "loaded Mattia"])
t.end()
}
)
})
示例5: MockScopedHttpClient
test.cb('appveyor > build', (t) => {
const token = 'my-token';
const account = 'my-account';
const project = 'my-project';
const response = {
"buildId": 136709,
"jobs": [],
"buildNumber": 7,
"version": "1.0.7",
"message": "replaced with command [skip ci]",
"branch": "master",
"commitId": "c2892a70d60c96c1b65a7c665ab806b7731fea8a",
"authorName": "Feodor Fitsner",
"authorUsername": "FeodorFitsner",
"committerName": "Feodor Fitsner",
"committerUsername": "FeodorFitsner",
"committed": "2014-08-15T22:05:54+00:00",
"messages": [],
"status": "queued",
"created": "2014-08-16T00:40:38.1703914+00:00"
};
const httpClient = new MockScopedHttpClient();
const headerSpy = sinon.spy(httpClient, 'header');
const postStub = sinon.stub(httpClient, 'post');
postStub.returns((handler: IHttpClientHandler) => {
handler(null, { statusCode: 200 }, JSON.stringify(response));
});
const httpStub = sinon.stub().returns(httpClient);
const appveyor = new AppVeyor(httpStub, token, account);
const result = appveyor.build(project);
sinon.assert.calledWith(httpStub, 'https://ci.appveyor.com/api/builds');
sinon.assert.calledWith(headerSpy, 'Authorization', `Bearer ${token}`);
sinon.assert.calledWith(headerSpy, 'Content-Type', 'application/json');
sinon.assert.calledWith(headerSpy, 'Accept', 'application/json');
sinon.assert.calledWith(postStub, `{"accountName":"${account}","projectSlug":"${project}"}`);
result.then((data) => {
t.is(data.ok, true);
t.is(data.statusCode, 200);
t.is(data.body.accountName, account);
t.is(data.body.projectSlug, project);
t.is(data.body.version, response.version);
t.is(data.body.link, `https://ci.appveyor.com/project/${account}/${project}/build/${response.version}`);
t.end();
}).catch(t.end);
});