forked from primefaces/primeng
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(testing): add jest in context of primefaces#15009
NOTE: 1. Configured jest according to https://thymikee.github.io/jest-preset-angular/docs/getting-started/installation 2. In was recommended in diverse sources to comment out the files in `tsconfig.spec.json` to avoid conflicts with jest
- Loading branch information
1 parent
f00d74b
commit 6b99b33
Showing
8 changed files
with
1,322 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/** | ||
* This is a basic test file is to test | ||
* if your current test tooling works in general. | ||
*/ | ||
import { Component } from '@angular/core'; | ||
import { TestBed } from '@angular/core/testing'; | ||
|
||
interface MyInterface { | ||
name: string; | ||
} | ||
|
||
@Component({ | ||
template: `` | ||
}) | ||
class DummyComponent {} | ||
|
||
function p1(): MyInterface { | ||
return { name: 'p1' }; | ||
} | ||
|
||
describe('test', () => { | ||
it('p1', () => { | ||
expect(p1().name).toBe('p1'); | ||
}); | ||
|
||
it('should create dummy component', () => { | ||
TestBed.configureTestingModule({ | ||
declarations: [DummyComponent] | ||
}).compileComponents(); | ||
|
||
const fixture = TestBed.createComponent(DummyComponent); | ||
const component = fixture.componentInstance; | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import type { Config } from 'jest'; | ||
|
||
const config: Config = { | ||
collectCoverage: true, | ||
coverageReporters: ['html'], | ||
preset: 'jest-preset-angular', | ||
moduleNameMapper: { | ||
'^primeng/(.*)': '<rootDir>/packages/primeng/src/$1/public_api' | ||
}, | ||
setupFilesAfterEnv: ['<rootDir>/setup-jest.ts'] | ||
}; | ||
|
||
export default config; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,7 +32,9 @@ | |
"format:check": "prettier --check \"**/*.{js,mjs,ts,mts,d.ts,html}\"", | ||
"lint": "eslint --ext \".js,.mjs,.ts,.mts\" --ignore-path .gitignore . --cache", | ||
"lint:fix": "eslint --fix --ext \".js,.mjs,.ts,.mts\" --ignore-path .gitignore .", | ||
"test:unit": "pnpm --filter primeng test:unit" | ||
"test:unit": "pnpm --filter primeng test:unit", | ||
"test:jest": "jest", | ||
"test:confirm-jest": "jest basic-test.spec.ts" | ||
}, | ||
"devDependencies": { | ||
"@angular-devkit/build-angular": "catalog:angular19", | ||
|
@@ -61,10 +63,13 @@ | |
"fs-extra": "^11.2.0", | ||
"glob": "^10.4.2", | ||
"husky": "^9.1.6", | ||
"jest": "^29.7.0", | ||
"jest-preset-angular": "^14.3.1", | ||
"lint-staged": "^12.0.0", | ||
"ng-packagr": "catalog:angular19", | ||
"pnpm": "^9.6.0", | ||
"prettier": "^3.0.0", | ||
"ts-jest": "^29.2.5", | ||
"tsup": "^8.1.0", | ||
"typescript": "catalog:angular19" | ||
}, | ||
|
@@ -73,6 +78,8 @@ | |
}, | ||
"packageManager": "[email protected]", | ||
"lint-staged": { | ||
"**/*.{js,mjs,ts,mts,d.ts,html}": ["prettier --write"] | ||
"**/*.{js,mjs,ts,mts,d.ts,html}": [ | ||
"prettier --write" | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { TestBed } from '@angular/core/testing'; | ||
|
||
import { FiltersArg } from '../api/fitlersarg'; | ||
import { TableService } from './table.service'; | ||
|
||
describe('TableService', () => { | ||
describe('filter entries', () => { | ||
describe('by single field aka locally', () => { | ||
let service: TableService; | ||
|
||
beforeEach(() => { | ||
// DEBUG! Prove this in the official docs | ||
TestBed.configureTestingModule({ | ||
providers: [TableService] | ||
}); | ||
service = TestBed.inject(TableService); | ||
}); | ||
|
||
it('should filter by starts with', () => { | ||
const data = [{ name: 'foo' }, { name: 'bar' }]; | ||
const filters: FiltersArg = { | ||
name: { | ||
value: 'f', | ||
matchMode: 'startsWith' | ||
} | ||
}; | ||
|
||
const result = service.filter(data, filters, [], 'startsWith'); | ||
expect(result).toEqual([{ name: 'foo' }]); | ||
}); | ||
}); | ||
describe('by all fields aka globally', () => {}); | ||
}); | ||
}); |
Oops, something went wrong.