Installation
Install Behavioral with dependencies all at once with following command:
- NPM
- Yarn
- PNPM
npm install --save-dev reflect-metadata jest typescript ts-jest @types/jest @typedtools/behavioral @typedtools/behavioral-jest
yarn add --dev reflect-metadata jest typescript ts-jest @types/jest @typedtools/behavioral @typedtools/behavioral-jest
pnpm add --save-dev reflect-metadata jest typescript ts-jest @types/jest @typedtools/behavioral @typedtools/behavioral-jest
Configure typescript
Behavioral uses decorators which are not turned on by default. Update your tsconfig.json file with the following options:
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
Configure jest
Behavioral requires typescript which is not available in Jest by default. To add support for typescript configure ts-jest with the following command:
- NPM
- Yarn
npx ts-jest config:init
yarn ts-jest config:init
This command will create jest.config.js
in project root directory. Needs to be updated about setup file with following content:
- jest.config.js
- setup.ts
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
testMatch: ["**/*.feature", "**/*.{spec,test}.{ts,js}"],
moduleFileExtensions: ['feature', 'js', 'mjs', 'ts'],
transform: {
"\.feature$": "@typedtools/behavioral-jest"
},
setupFilesAfterEnv: ['<rootDir>/setup.ts'],
};
import 'reflect-metadata';
And that's it you are ready to go ๐