You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
50 lines
1.2 KiB
50 lines
1.2 KiB
describe("sample", function(){
|
|
|
|
it("should return testdata", function(){
|
|
expect(testfunc()).toEqual('testdata');
|
|
});
|
|
|
|
|
|
it("checks that async / await works", async() => {
|
|
function asyncFunctionSample(x) {
|
|
return new Promise(
|
|
resolve => {
|
|
setTimeout( () => {resolve(x); }, 3000);
|
|
}
|
|
/*,
|
|
reject => {
|
|
setTimeout(()=> {reject(x);}, 2000);
|
|
}*/
|
|
);
|
|
}
|
|
|
|
async function check(x) {
|
|
var retval = asyncFunctionSample(10);
|
|
return x + await retval;
|
|
}
|
|
|
|
var v = await check(10);
|
|
expect(v).toBe(20);
|
|
|
|
|
|
});
|
|
|
|
|
|
it ("checks allowing creating rejected promises", (done) => {
|
|
Promise.reject('some reason').catch(done);
|
|
});
|
|
|
|
it('checks that promises work', function() {
|
|
function someAsyncFunction(x) {
|
|
return new Promise(
|
|
resolve => {
|
|
setTimeout(()=> {resolve(x*2);}, 3000);
|
|
}
|
|
);
|
|
}
|
|
return someAsyncFunction(10).then(function (result) {
|
|
expect(result).toEqual(20);
|
|
});
|
|
});
|
|
|
|
});
|