smartcache/test/test.ts

52 lines
1.3 KiB
TypeScript
Raw Normal View History

2018-08-19 19:19:23 +00:00
import { expect, tap } from "@pushrocks/tapbundle";
2018-07-12 21:52:06 +00:00
import * as smartcache from "../ts/index";
import * as smartdelay from "@pushrocks/smartdelay";
2018-07-12 19:32:20 +00:00
2018-07-12 21:52:06 +00:00
let smartcacheInstance: smartcache.SmartCache;
2018-07-12 19:32:20 +00:00
2018-07-12 21:52:06 +00:00
tap.test("should create a valid instance of SmartCache", async () => {
smartcacheInstance = new smartcache.SmartCache();
expect(smartcacheInstance).to.be.instanceof(smartcache.SmartCache);
});
tap.test("try to get async responses", async () => {
const getResponse = async () => {
const response = await smartcacheInstance
.cacheReturn(async () => {
console.log("function ran");
return "hello";
}, 1000)
.catch(err => {
console.log(err);
});
console.log("response is:");
console.log(response);
};
2018-07-12 19:32:20 +00:00
2018-07-12 21:52:06 +00:00
const getResponse2 = async () => {
const response = await smartcacheInstance
.cacheReturn(async () => {
console.log("function 2 ran");
return "hello";
}, 1000)
.catch(err => {
console.log(err);
});
console.log("response is:");
console.log(response);
};
getResponse();
2018-07-12 19:32:20 +00:00
getResponse();
2018-07-12 21:52:06 +00:00
getResponse2();
getResponse2();
smartdelay.delayFor(1000).then(() => {
getResponse();
// getResponse2();
});
2018-07-12 19:32:20 +00:00
});
2018-07-12 21:52:06 +00:00
tap.start({
throwOnError: true
});