2022-08-25 11:47:54 +02:00
|
|
|
import chai from "chai"
|
|
|
|
import freesewing from "./dist/index.mjs"
|
|
|
|
|
|
|
|
const expect = chai.expect
|
2018-08-12 13:32:53 +02:00
|
|
|
|
2022-08-27 09:27:07 +02:00
|
|
|
const pattern = new freesewing.Pattern();
|
|
|
|
const store = pattern.store;
|
2018-08-12 13:32:53 +02:00
|
|
|
|
2022-08-27 09:27:07 +02:00
|
|
|
describe('Store', () => {
|
|
|
|
it("Store should be a Map", () => {
|
|
|
|
expect(store.data.toString()).to.equal("[object Map]");
|
|
|
|
});
|
2018-08-12 13:32:53 +02:00
|
|
|
|
2022-08-27 09:27:07 +02:00
|
|
|
it("Should set/get a store value", () => {
|
|
|
|
store.set("foo", "bar");
|
|
|
|
expect(store.get("foo")).to.equal("bar");
|
|
|
|
});
|
2018-08-12 13:32:53 +02:00
|
|
|
|
2022-08-27 09:27:07 +02:00
|
|
|
it("Should set a store value only if unset", () => {
|
|
|
|
store.setIfUnset("few", "baz");
|
|
|
|
store.setIfUnset("few", "schmoo");
|
|
|
|
expect(store.get("few")).to.equal("baz");
|
|
|
|
});
|
2022-07-30 20:02:42 +02:00
|
|
|
|
2022-08-27 09:27:07 +02:00
|
|
|
it("Should raise a warning when retrieving a invalid key", () => {
|
|
|
|
store.get('nope')
|
|
|
|
expect(pattern.events.warning.length).to.equal(1)
|
|
|
|
expect(pattern.events.warning[0]).to.equal('Tried to access `nope` in the `store` but it is not set')
|
|
|
|
});
|
2022-07-30 20:02:42 +02:00
|
|
|
});
|
|
|
|
|