Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
aanthonymax committed Nov 19, 2024
1 parent d7a1037 commit ad6108a
Showing 1 changed file with 75 additions and 18 deletions.
93 changes: 75 additions & 18 deletions test/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
ID,
INDICATORS,
MEMO,
METHOD,
MODE,
PARSE_ERROR,
RENDER_ERROR,
Expand All @@ -21,29 +22,29 @@ import { HMPLRequestInfo } from "../src/types";
* Function "compile"
*/

describe("compile function", () => {
const e = (text: string, block: () => unknown, message: string) => {
it(text, () => {
assert.throws(block, {
message
});
const e = (text: string, block: () => unknown, message: string) => {
it(text, () => {
assert.throws(block, {
message
});
};
});
};

const createTestObj1 = (obj: Record<string, any>) => {
return `<div>{${stringify(obj as HMPLRequestInfo)}}</div>`;
};
const eq = (text: string, block: unknown, equality: any) => {
it(text, () => {
assert.strictEqual(block, equality);
});
};

const createTestObj2 = (text: string) => {
return `<div>${text}</div>`;
};
const createTestObj1 = (obj: Record<string, any>) => {
return `<div>{${stringify(obj as HMPLRequestInfo)}}</div>`;
};

const eq = (text: string, block: unknown, equality: any) => {
it(text, () => {
assert.strictEqual(block, equality);
});
};
const createTestObj2 = (text: string) => {
return `<div>${text}</div>`;
};

describe("compile function", () => {
e(
"",
() => compile(123 as any),
Expand Down Expand Up @@ -157,3 +158,59 @@ describe("compile function", () => {
true
);
});

/**
* Function "stringify"
*/

describe("stringify function", () => {
eq(
"",
stringify({ src: "/api/test", method: "GET" }),
'{"src":"/api/test","method":"GET"}'
);
});

/**
* Template function
*/

describe("template function", () => {
e(
"",
() =>
compile(
createTestObj2(
`<button>Click</button>{{ "src":"/api/test", "method": "test", "after": "click:#increment" }}`
)
)(),
`${REQUEST_OBJECT_ERROR}: The "${METHOD}" property has only GET, POST, PUT, PATCH or DELETE values`
);
// e(
// "",
// () =>
// compile(
// `{{ "src":"/api/test", "method": "test", "after": "click:#increment" }}`
// )(),
// `${REQUEST_OBJECT_ERROR}: The "${METHOD}" property has only GET, POST, PUT, PATCH or DELETE values`
// );
e(
"",
() =>
compile(
createTestObj2(
`<button>Click</button>{{ "src":"/api/test", "after":"click:#increment" }}`
)
)(),
`${RENDER_ERROR}: Selectors nodes not found`
);
eq(
"",
compile(
createTestObj2(
`<button id="increment">Click</button>{{ "src":"/api/test", "after":"click:#increment" }}`
)
)().response?.outerHTML,
'<div><button id="increment">Click</button><!--hmpl0--></div>'
);
});

0 comments on commit ad6108a

Please sign in to comment.