Add first frontend tests for helpers.ts
This commit is contained in:
parent
45fef12590
commit
ba4771614d
5
frontend/leeds-beer-quest/jest.config.cjs
Normal file
5
frontend/leeds-beer-quest/jest.config.cjs
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
/** @type {import('ts-jest').JestConfigWithTsJest} */
|
||||||
|
module.exports = {
|
||||||
|
preset: 'ts-jest',
|
||||||
|
testEnvironment: 'node',
|
||||||
|
};
|
9046
frontend/leeds-beer-quest/package-lock.json
generated
9046
frontend/leeds-beer-quest/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -6,7 +6,8 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite",
|
"dev": "vite",
|
||||||
"build": "tsc && vite build",
|
"build": "tsc && vite build",
|
||||||
"preview": "vite preview"
|
"preview": "vite preview",
|
||||||
|
"test": "jest"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@emotion/react": "^11.10.5",
|
"@emotion/react": "^11.10.5",
|
||||||
@ -21,9 +22,12 @@
|
|||||||
"sort-by": "^1.2.0"
|
"sort-by": "^1.2.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"@testing-library/react": "^13.4.0",
|
||||||
"@types/react": "^18.0.22",
|
"@types/react": "^18.0.22",
|
||||||
"@types/react-dom": "^18.0.7",
|
"@types/react-dom": "^18.0.7",
|
||||||
"@vitejs/plugin-react": "^2.2.0",
|
"@vitejs/plugin-react": "^2.2.0",
|
||||||
|
"jest": "^29.2.2",
|
||||||
|
"ts-jest": "^29.0.3",
|
||||||
"typescript": "^4.6.4",
|
"typescript": "^4.6.4",
|
||||||
"vite": "^3.2.0"
|
"vite": "^3.2.0"
|
||||||
}
|
}
|
||||||
|
43
frontend/leeds-beer-quest/src/tests/helpers.spec.ts
Normal file
43
frontend/leeds-beer-quest/src/tests/helpers.spec.ts
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
import { ArrayToArrayUrlParams } from "../lib/helpers";
|
||||||
|
import { expect, describe, it } from '@jest/globals';
|
||||||
|
|
||||||
|
const exampleParamName = "testParamName";
|
||||||
|
|
||||||
|
const exampleTestParams = ["one", "two", "three", "four", "five"];
|
||||||
|
|
||||||
|
describe("Given the ArrayToArrayUrlParams function", () => {
|
||||||
|
describe("and the param array is empty", () => {
|
||||||
|
it("should return empty string", () => {
|
||||||
|
const paramResult = ArrayToArrayUrlParams("testParam", []);
|
||||||
|
|
||||||
|
expect(paramResult).toHaveLength(0);
|
||||||
|
expect(paramResult).toBe("");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("and the params are not the first in the param line", () => {
|
||||||
|
it("should return & as the first char, not ?", () => {
|
||||||
|
const paramResult = ArrayToArrayUrlParams("testParam", exampleTestParams, false);
|
||||||
|
|
||||||
|
expect(paramResult[0]).toBe("&");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("and the param array has values", () => {
|
||||||
|
it("should not return a string ending with &", () => {
|
||||||
|
const paramResult = ArrayToArrayUrlParams("testParam", exampleTestParams);
|
||||||
|
|
||||||
|
expect(paramResult[paramResult.length - 1]).not.toBe("&");
|
||||||
|
});
|
||||||
|
|
||||||
|
it.each([
|
||||||
|
[exampleTestParams, `?${exampleParamName}=${exampleTestParams[0]}&${exampleParamName}=${exampleTestParams[1]}&${exampleParamName}=${exampleTestParams[2]}&${exampleParamName}=${exampleTestParams[3]}&${exampleParamName}=${exampleTestParams[4]}`],
|
||||||
|
[["a", "b", "c"], `?${exampleParamName}=a&${exampleParamName}=b&${exampleParamName}=c`],
|
||||||
|
[["onlyParam"], `?${exampleParamName}=onlyParam`]
|
||||||
|
])("should return a url parameter string with the included data", (params: string[], expectedResult: string) => {
|
||||||
|
const paramResult = ArrayToArrayUrlParams(exampleParamName, params);
|
||||||
|
|
||||||
|
expect(paramResult).toBe(expectedResult);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
Loading…
Reference in New Issue
Block a user