2018-06-15 11:03:24 -04:00
|
|
|
import PreloadStore from "preload-store";
|
2020-02-05 11:14:42 -05:00
|
|
|
import { Promise } from "rsvp";
|
2015-08-11 12:27:07 -04:00
|
|
|
|
2017-06-14 13:57:58 -04:00
|
|
|
QUnit.module("preload-store", {
|
|
|
|
beforeEach() {
|
2018-06-15 11:03:24 -04:00
|
|
|
PreloadStore.store("bane", "evil");
|
2013-06-19 15:06:23 -04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2017-06-14 13:57:58 -04:00
|
|
|
QUnit.test("get", assert => {
|
2018-06-15 11:03:24 -04:00
|
|
|
assert.blank(PreloadStore.get("joker"), "returns blank for a missing key");
|
|
|
|
assert.equal(
|
|
|
|
PreloadStore.get("bane"),
|
|
|
|
"evil",
|
|
|
|
"returns the value for that key"
|
|
|
|
);
|
2013-06-19 15:06:23 -04:00
|
|
|
});
|
|
|
|
|
2017-06-14 13:57:58 -04:00
|
|
|
QUnit.test("remove", assert => {
|
2018-06-15 11:03:24 -04:00
|
|
|
PreloadStore.remove("bane");
|
|
|
|
assert.blank(PreloadStore.get("bane"), "removes the value if the key exists");
|
2013-06-19 15:06:23 -04:00
|
|
|
});
|
|
|
|
|
2020-03-02 15:20:19 -05:00
|
|
|
QUnit.test(
|
2018-06-15 11:03:24 -04:00
|
|
|
"getAndRemove returns a promise that resolves to null",
|
2020-03-02 15:20:19 -05:00
|
|
|
async assert => {
|
|
|
|
assert.blank(await PreloadStore.getAndRemove("joker"));
|
2018-06-15 11:03:24 -04:00
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2020-03-02 15:20:19 -05:00
|
|
|
QUnit.test(
|
2018-06-15 11:03:24 -04:00
|
|
|
"getAndRemove returns a promise that resolves to the result of the finder",
|
2020-03-02 15:20:19 -05:00
|
|
|
async assert => {
|
|
|
|
const finder = () => "batdance";
|
|
|
|
const result = await PreloadStore.getAndRemove("joker", finder);
|
2018-06-15 11:03:24 -04:00
|
|
|
|
2020-03-02 15:20:19 -05:00
|
|
|
assert.equal(result, "batdance");
|
2018-06-15 11:03:24 -04:00
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2020-03-02 15:20:19 -05:00
|
|
|
QUnit.test(
|
2018-06-15 11:03:24 -04:00
|
|
|
"getAndRemove returns a promise that resolves to the result of the finder's promise",
|
2020-03-02 15:20:19 -05:00
|
|
|
async assert => {
|
|
|
|
const finder = () => Promise.resolve("hahahah");
|
|
|
|
const result = await PreloadStore.getAndRemove("joker", finder);
|
2018-06-15 11:03:24 -04:00
|
|
|
|
2020-03-02 15:20:19 -05:00
|
|
|
assert.equal(result, "hahahah");
|
2018-06-15 11:03:24 -04:00
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2020-03-02 15:20:19 -05:00
|
|
|
QUnit.test(
|
2018-06-15 11:03:24 -04:00
|
|
|
"returns a promise that rejects with the result of the finder's rejected promise",
|
2020-03-02 15:20:19 -05:00
|
|
|
async assert => {
|
|
|
|
const finder = () => Promise.reject("error");
|
2018-06-15 11:03:24 -04:00
|
|
|
|
2020-03-02 15:20:19 -05:00
|
|
|
await PreloadStore.getAndRemove("joker", finder).catch(result => {
|
2018-06-15 11:03:24 -04:00
|
|
|
assert.equal(result, "error");
|
|
|
|
});
|
|
|
|
}
|
|
|
|
);
|
2013-06-19 15:06:23 -04:00
|
|
|
|
2020-03-02 15:20:19 -05:00
|
|
|
QUnit.test("returns a promise that resolves to 'evil'", async assert => {
|
|
|
|
const result = await PreloadStore.getAndRemove("bane");
|
|
|
|
assert.equal(result, "evil");
|
2013-06-19 15:06:23 -04:00
|
|
|
});
|