1
0
Fork 0
mirror of synced 2024-07-03 21:40:55 +12:00

Type tests

This commit is contained in:
Adria Navarro 2024-03-15 09:41:32 +01:00
parent 972cbf43b8
commit 4332034434
6 changed files with 16 additions and 16 deletions

View file

@ -157,7 +157,7 @@ export function processObjectSync(
*/
export function processStringSync(
string: string,
context: object,
context?: object,
opts?: ProcessOptions
): string {
// Take a copy of input in case of error

View file

@ -1,6 +1,6 @@
import { convertToJS } from "../src/index"
function checkLines(response, lines) {
function checkLines(response: string, lines: string[]) {
const toCheck = response.split("\n")
let count = 0
for (let line of lines) {

View file

@ -271,7 +271,7 @@ describe("test the string helpers", () => {
})
describe("test the comparison helpers", () => {
async function compare(func, a, b) {
async function compare(func: string, a: any, b: any) {
const output = await processString(
`{{ #${func} a b }}Success{{ else }}Fail{{ /${func} }}`,
{

View file

@ -3,7 +3,7 @@ import vm from "vm"
import { processStringSync, encodeJSBinding, setJSRunner } from "../src/index"
import { UUID_REGEX } from "./constants"
const processJS = (js, context?): any => {
const processJS = (js: string, context?: object): any => {
return processStringSync(encodeJSBinding(js), context)
}

View file

@ -24,7 +24,7 @@ import { getParsedManifest, runJsHelpersTests } from "./utils"
tk.freeze("2021-01-21T12:00:00")
function escapeRegExp(string) {
function escapeRegExp(string: string) {
return string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&") // $& means the whole matched string
}
@ -40,9 +40,9 @@ describe("manifest", () => {
describe("examples are valid", () => {
describe.each(Object.keys(manifest))("%s", collection => {
it.each(manifest[collection])("%s", async (_, { hbs, js }) => {
const context = {
double: i => i * 2,
isString: x => typeof x === "string",
const context: any = {
double: (i: number) => i * 2,
isString: (x: any) => typeof x === "string",
}
const arrays = hbs.match(/\[[^/\]]+\]/)

View file

@ -3,7 +3,7 @@ import { getJsHelperList } from "../src/helpers"
import { convertToJS, processStringSync, encodeJSBinding } from "../src/index"
function tryParseJson(str) {
function tryParseJson(str: string) {
if (typeof str !== "string") {
return
}
@ -25,7 +25,7 @@ type ExampleType = [
]
export const getParsedManifest = () => {
const manifest = getManifest()
const manifest: any = getManifest()
const collections = Object.keys(manifest)
const examples = collections.reduce((acc, collection) => {
@ -73,14 +73,14 @@ export const runJsHelpersTests = ({
funcWrap?: any
testsToSkip?: any
} = {}) => {
funcWrap = funcWrap || (delegate => delegate())
funcWrap = funcWrap || ((delegate: () => any) => delegate())
const manifest = getParsedManifest()
const processJS = (js, context) => {
const processJS = (js: string, context: object | undefined) => {
return funcWrap(() => processStringSync(encodeJSBinding(js), context))
}
function escapeRegExp(string) {
function escapeRegExp(string: string) {
return string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&") // $& means the whole matched string
}
@ -98,9 +98,9 @@ export const runJsHelpersTests = ({
examplesToRun.length &&
it.each(examplesToRun)("%s", async (_, { hbs, js }) => {
const context = {
double: i => i * 2,
isString: x => typeof x === "string",
const context: any = {
double: (i: number) => i * 2,
isString: (x: any) => typeof x === "string",
}
const arrays = hbs.match(/\[[^/\]]+\]/)