test: sorting

This commit is contained in:
Térence Hollander
2021-08-30 13:45:35 +02:00
parent eb9fa40224
commit b241f7c40b
5 changed files with 5848 additions and 10 deletions

1
.gitignore vendored
View File

@@ -4,3 +4,4 @@ node_modules
/.svelte-kit /.svelte-kit
/build /build
/functions /functions
coverage

5
jest.config.cjs Normal file
View File

@@ -0,0 +1,5 @@
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
};

5784
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -7,11 +7,13 @@
"build": "svelte-kit build", "build": "svelte-kit build",
"preview": "svelte-kit preview", "preview": "svelte-kit preview",
"lint": "prettier --check . && eslint --ignore-path .gitignore .", "lint": "prettier --check . && eslint --ignore-path .gitignore .",
"format": "prettier --write ." "format": "prettier --write .",
"test": "jest"
}, },
"devDependencies": { "devDependencies": {
"@sveltejs/adapter-static": "next", "@sveltejs/adapter-static": "next",
"@sveltejs/kit": "next", "@sveltejs/kit": "next",
"@types/jest": "^27.0.1",
"@typescript-eslint/eslint-plugin": "^4.19.0", "@typescript-eslint/eslint-plugin": "^4.19.0",
"@typescript-eslint/parser": "^4.19.0", "@typescript-eslint/parser": "^4.19.0",
"autoprefixer": "^10.3.1", "autoprefixer": "^10.3.1",
@@ -19,6 +21,7 @@
"eslint": "^7.22.0", "eslint": "^7.22.0",
"eslint-config-prettier": "^8.1.0", "eslint-config-prettier": "^8.1.0",
"eslint-plugin-svelte3": "^3.2.0", "eslint-plugin-svelte3": "^3.2.0",
"jest": "^27.1.0",
"mdsvex": "^0.9.3", "mdsvex": "^0.9.3",
"postcss": "^8.3.5", "postcss": "^8.3.5",
"postcss-load-config": "^3.1.0", "postcss-load-config": "^3.1.0",
@@ -26,9 +29,10 @@
"prettier-plugin-svelte": "^2.2.0", "prettier-plugin-svelte": "^2.2.0",
"svelte": "^3.38.2", "svelte": "^3.38.2",
"svelte-preprocess": "^4.7.4", "svelte-preprocess": "^4.7.4",
"tailwindcss": "^2.2.4",
"ts-jest": "^27.0.5",
"tslib": "^2.0.0", "tslib": "^2.0.0",
"typescript": "^4.0.0", "typescript": "^4.4.2"
"tailwindcss": "^2.2.4"
}, },
"type": "module", "type": "module",
"dependencies": { "dependencies": {

View File

@@ -0,0 +1,58 @@
import { compare } from './sort';
describe("sort", () => {
const mock = [{
"addedOn": "2019-09-29T14:39:13Z",
"category": "Svelte",
"description": "Boilerplate with TypeScript, Webpack, Storybook, Travis CI, SCSS, Babel, EsLint, Prettier, Jest",
"stars": 51,
"tags": [],
"title": "agusID/boilerplate-svelte",
"url": "https://github.com/agusID/boilerplate-svelte"
},
{
"addedOn": "2020-09-29T14:39:13Z",
"category": "Svelte",
"description": "An example repo of a Svelte app that is IE11 compatible",
"stars": 27,
"tags": [],
"title": "angelozehr/svelte-example-museums",
"url": "https://github.com/angelozehr/svelte-example-museums"
}];
it("should sort by added_desc", () => {
mock.sort(compare("added_desc"));
expect(mock[0].title).toEqual("angelozehr/svelte-example-museums");
expect(mock[1].title).toEqual("agusID/boilerplate-svelte");
});
it("should sort by added_asc", () => {
mock.sort(compare("added_asc"));
expect(mock[0].title).toEqual("agusID/boilerplate-svelte");
expect(mock[1].title).toEqual("angelozehr/svelte-example-museums");
});
it("should sort by name_asc", () => {
mock.sort(compare("name_asc"));
expect(mock[0].title).toEqual("agusID/boilerplate-svelte");
expect(mock[1].title).toEqual("angelozehr/svelte-example-museums");
});
it("should sort by name_desc", () => {
mock.sort(compare("name_desc"));
expect(mock[0].title).toEqual("angelozehr/svelte-example-museums");
expect(mock[1].title).toEqual("agusID/boilerplate-svelte");
});
it("should sort by stars_asc", () => {
mock.sort(compare("stars_asc"));
expect(mock[0].title).toEqual("angelozehr/svelte-example-museums");
expect(mock[1].title).toEqual("agusID/boilerplate-svelte");
});
it("should sort by stars_desc", () => {
mock.sort(compare("stars_desc"));
expect(mock[0].title).toEqual("agusID/boilerplate-svelte");
expect(mock[1].title).toEqual("angelozehr/svelte-example-museums");
});
});