Add Jest for testing with one test
This commit is contained in:
parent
25bd910eb4
commit
49850634e1
|
@ -19,3 +19,6 @@ yarn-error.log*
|
|||
*.njsproj
|
||||
*.sln
|
||||
*.sw?
|
||||
|
||||
# Jest coverage report
|
||||
/coverage
|
||||
|
|
|
@ -26,6 +26,13 @@ This custom one uses eslint directly, and doesn't automatically fix issues.
|
|||
npm run eslint
|
||||
```
|
||||
|
||||
### Jest testing
|
||||
|
||||
```
|
||||
npm run test
|
||||
npm run test:coverage
|
||||
```
|
||||
|
||||
#### Check for specific issues
|
||||
```
|
||||
npm run lint | grep require-returns
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
import World from 'src/models/World';
|
||||
|
||||
const world = new World();
|
||||
|
||||
test('World has empty journal', () => {
|
||||
expect(world.journal.count()).toBe(0);
|
||||
});
|
|
@ -0,0 +1,26 @@
|
|||
|
||||
module.exports = {
|
||||
preset: 'ts-jest',
|
||||
testEnvironment: 'node',
|
||||
roots: [
|
||||
'<rootDir>'
|
||||
],
|
||||
modulePaths: [
|
||||
'<rootDir>'
|
||||
],
|
||||
// An array of glob patterns indicating a set of files for which coverage information should be collected
|
||||
collectCoverageFrom: [
|
||||
"<rootDir>/src/**/*.ts",
|
||||
"!<rootDir>/src/**/*.d.ts"
|
||||
],
|
||||
|
||||
// The directory where Jest should output its coverage files
|
||||
//coverageDirectory: "coverage",
|
||||
/*moduleNameMapper: {
|
||||
'^@/(.*)$': '<rootDir>/src/$1'
|
||||
},*/
|
||||
globals: {
|
||||
'ts-jest': {
|
||||
}
|
||||
}
|
||||
};
|
File diff suppressed because it is too large
Load Diff
|
@ -6,8 +6,10 @@
|
|||
"serve": "vue-cli-service serve",
|
||||
"build": "vue-cli-service build --modern",
|
||||
"lint": "vue-cli-service lint",
|
||||
"eslint": "eslint ./src --ext .js,.jsx,.ts,.tsx,.vue || (exit 0)",
|
||||
"docs": "typedoc --out docs src && http-server docs"
|
||||
"eslint": "eslint ./src --ext .js,.jsx,.ts,.tsx,.vue || (exit 0)",
|
||||
"docs": "typedoc --out docs src && http-server docs",
|
||||
"test": "jest",
|
||||
"test:coverage": "jest --coverage"
|
||||
},
|
||||
"dependencies": {
|
||||
"@vue/eslint-config-typescript": "^5.0.2",
|
||||
|
@ -19,6 +21,7 @@
|
|||
"vue-property-decorator": "^9.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/jest": "^26.0.8",
|
||||
"@typescript-eslint/eslint-plugin": "^3.7.1",
|
||||
"@typescript-eslint/parser": "^3.7.1",
|
||||
"@vue/cli-plugin-eslint": "^4.4.6",
|
||||
|
@ -27,6 +30,8 @@
|
|||
"eslint": "^7.5.0",
|
||||
"eslint-plugin-jsdoc": "^30.0.3",
|
||||
"eslint-plugin-vue": "^6.1.2",
|
||||
"jest": "^26.2.2",
|
||||
"ts-jest": "^26.1.4",
|
||||
"typescript": "^3.9.7",
|
||||
"vue-template-compiler": "^2.6.11"
|
||||
}
|
||||
|
|
|
@ -17,6 +17,15 @@ export default class Journal {
|
|||
this.entries.push(new JournalEntry(currentMoment, message));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of entries in the journal.
|
||||
*
|
||||
* @returns Number of entries.
|
||||
*/
|
||||
public count(): number {
|
||||
return this.entries.length;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes all entries from the journal.
|
||||
*/
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
"extends": "./tsconfig.json",
|
||||
"exclude": [
|
||||
"**/*.spec.ts",
|
||||
"**/*.test.ts",
|
||||
]
|
||||
}
|
|
@ -13,7 +13,8 @@
|
|||
"sourceMap": true,
|
||||
"baseUrl": ".",
|
||||
"types": [
|
||||
"webpack-env"
|
||||
"jest",
|
||||
"webpack-env"
|
||||
],
|
||||
"paths": {
|
||||
"@/*": [
|
||||
|
@ -32,8 +33,8 @@
|
|||
"src/**/*.ts",
|
||||
"src/**/*.tsx",
|
||||
"src/**/*.vue",
|
||||
"tests/**/*.ts",
|
||||
"tests/**/*.tsx"
|
||||
"__tests__/**/*.ts",
|
||||
"__tests__/**/*.tsx"
|
||||
],
|
||||
"exclude": [
|
||||
"node_modules"
|
||||
|
|
Loading…
Reference in New Issue