Skip to content

Commit

Permalink
updatedtests
Browse files Browse the repository at this point in the history
  • Loading branch information
TzeYiing committed Feb 12, 2021
1 parent 84a9e2b commit bc6f78c
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 71 deletions.
35 changes: 35 additions & 0 deletions test/features.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import assert from "assert";
import Core from "../lib";

describe("features", function () {
let core;
it("a feature's schema is loaded", async function () {
const cards = {
schema: `
create table if not exists cards(
id INTEGER PRIMARY KEY
);`,
};
core = await Core.init({ features: [cards] }, { internals: true });

const tables = core._internals.listTables;
assert.ok(tables.includes("cards"));
});
it("a feature's handlers can be declared", async function () {
const cards = {
schema: `
create table if not exists cards(
id INTEGER PRIMARY KEY
);`,
handlers: {
myHandler: (handlerArg) => {
assert.ok(handlerArg);
return "myHandler";
},
},
};
core = await Core.init({ features: { cards } });
const result = core.cards.myhandler();
assert.strictEqual(result, "myHandler");
});
});
18 changes: 0 additions & 18 deletions test/features.test.ts

This file was deleted.

File renamed without changes.
17 changes: 17 additions & 0 deletions test/init.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import * as assert from "assert";
import Core, { App } from "../lib";

describe("init", function () {
let core: App;
it("before initialization, no other keys are set", async function () {
assert.ok("init" in Core);
assert.rejects("state" in Core);
core = await Core.init();
assert.ok("state" in core);
assert.ok("init" in core);
});
it("adds access to _internals when internals option is true", async function () {
core = await Core.init({}, { internals: true });
assert.ok("_internals" in core);
});
});
17 changes: 0 additions & 17 deletions test/init.test.ts

This file was deleted.

23 changes: 0 additions & 23 deletions test/pushState.test.ts

This file was deleted.

30 changes: 30 additions & 0 deletions test/state.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import assert from "assert";
import Core from "../lib";

describe("state", function () {
let core;
it("core.state is empty object by default", async function () {
core = await Core.init();
assert.strictEqual(core.state, {});
});
it("core.state returns declared state columns", async function () {
core = await Core.init({
stateColumns: ["my_column integer"],
});
assert.notStrictEqual(core.state, { my_column: null });
});

it("core.state calls buildState", async function () {
let calls = 0;
core = await Core.init({
buildState: (partial, core) => {
calls++;
assert.strictEqual(partial, {});
assert.ok(core); //gets a truthy value
return { my_state: true };
},
});
assert.strictEqual(calls, 1);
assert.strictEqual(core.state, { my_column: null });
});
});
13 changes: 0 additions & 13 deletions test/state.test.ts

This file was deleted.

0 comments on commit bc6f78c

Please sign in to comment.