Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import type { Config } from 'jest';

const config: Config = {
preset: 'jest-preset-angular',
testEnvironment: 'jsdom',
setupFilesAfterEnv: ['<rootDir>/setup-jest.ts'],
testMatch: ['**/?(*.)+(spec).ts'],
transform: {
'^.+\\.(ts|mjs|js)$': [
'jest-preset-angular',
{
tsconfig: '<rootDir>/tsconfig.spec.json',
},
],
},
moduleFileExtensions: ['ts', 'js', 'html'],
moduleNameMapper: {
'^@app/(.*)$': '<rootDir>/src/app/$1',
},
testPathIgnorePatterns: ['/node_modules/', '/dist/'],
reporters: ['default'],
};

export default config;


6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"test": "jest",
"lint": "ng lint --force",
"prepare": "husky install"
},
Expand Down Expand Up @@ -34,10 +34,14 @@
"@angular/build": "^20.0.0",
"@angular/cli": "^20.0.0",
"@angular/compiler-cli": "20.0.0",
"@types/jest": "^29.5.12",
"@types/marked": "^6.0.0",
"jest": "^29.7.0",
"jest-preset-angular": "^14.0.0",
"husky": "^8.0.3",
"lint-staged": "^16.1.2",
"prettier": "^3.1.1",
"ts-node": "^10.9.2",
"typescript": "~5.8.3"
},
"lint-staged": {
Expand Down
6 changes: 6 additions & 0 deletions setup-jest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import 'jest-preset-angular/setup-jest';

// Optional: mock for window.scrollTo etc. add minimal DOM APIs if needed
Object.defineProperty(window, 'scrollTo', { value: () => {}, writable: true });


25 changes: 25 additions & 0 deletions src/app/core/auth/services/jwt.service.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { TestBed } from "@angular/core/testing";
import { JwtService } from "./jwt.service";

describe("JwtService", () => {
let service: JwtService;

beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(JwtService);
window.localStorage.clear();
});

it("should save and get token", () => {
service.saveToken("abc123");
expect(service.getToken()).toBe("abc123");
});

it("should remove token on destroy", () => {
service.saveToken("xyz");
service.destroyToken();
expect(service.getToken()).toBeUndefined();
});
});


17 changes: 17 additions & 0 deletions src/app/shared/components/list-errors.component.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { ListErrorsComponent } from "./list-errors.component";

describe("ListErrorsComponent", () => {
it("should build errorList from Errors input", () => {
const cmp = new ListErrorsComponent();
cmp.errors = { errors: { email: "is invalid", password: "is too short" } };
expect(cmp.errorList).toEqual(["email is invalid", "password is too short"]);
});

it("should handle null input as empty list", () => {
const cmp = new ListErrorsComponent();
cmp.errors = null;
expect(cmp.errorList).toEqual([]);
});
});


19 changes: 19 additions & 0 deletions src/app/shared/pipes/markdown.pipe.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { TestBed } from "@angular/core/testing";
import { MarkdownPipe } from "./markdown.pipe";
import { DomSanitizer } from "@angular/platform-browser";

jest.mock("marked", () => ({
marked: {
parse: (content: string) => `<p>${content}</p>`,
},
}));

describe("MarkdownPipe", () => {
it("should render markdown to sanitized HTML", async () => {
const pipe = TestBed.runInInjectionContext(() => new MarkdownPipe());
const result = await pipe.transform("Hello");
expect(result).toBe("<p>Hello</p>");
});
});


2 changes: 1 addition & 1 deletion tsconfig.spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "./out-tsc/spec",
"types": ["jasmine"]
"types": ["jest", "node"]
},
"include": ["src/**/*.spec.ts", "src/**/*.d.ts"]
}