discourse/test/javascripts/lib/preload-store-test.js

Failed to ignore revisions in .git-blame-ignore-revs.

66 lines
1.7 KiB
JavaScript
Raw Normal View History

2018-06-15 11:03:24 -04:00
import PreloadStore from "preload-store";
import { Promise } from "rsvp";
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");
}
});
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"
);
});
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");
});
QUnit.test(
2018-06-15 11:03:24 -04:00
"getAndRemove returns a promise that resolves to null",
async assert => {
assert.blank(await PreloadStore.getAndRemove("joker"));
2018-06-15 11:03:24 -04:00
}
);
QUnit.test(
2018-06-15 11:03:24 -04:00
"getAndRemove returns a promise that resolves to the result of the finder",
async assert => {
const finder = () => "batdance";
const result = await PreloadStore.getAndRemove("joker", finder);
2018-06-15 11:03:24 -04:00
assert.equal(result, "batdance");
2018-06-15 11:03:24 -04: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",
async assert => {
const finder = () => Promise.resolve("hahahah");
const result = await PreloadStore.getAndRemove("joker", finder);
2018-06-15 11:03:24 -04:00
assert.equal(result, "hahahah");
2018-06-15 11:03:24 -04: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",
async assert => {
const finder = () => Promise.reject("error");
2018-06-15 11:03:24 -04:00
await PreloadStore.getAndRemove("joker", finder).catch(result => {
2018-06-15 11:03:24 -04:00
assert.equal(result, "error");
});
}
);
QUnit.test("returns a promise that resolves to 'evil'", async assert => {
const result = await PreloadStore.getAndRemove("bane");
assert.equal(result, "evil");
});