Write tests for flag evaluation, rule matching, percentage rollout, and edge cases. Test rule priority, attribute matching, segment membership. Use Jest with integration tests using testcontainers. By the end, flag logic is well-tested and confident.
← Back to Module 05 overviewInstall: npm install --save-dev jest ts-jest @types/jest testcontainers
Create jest.config.js:
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
roots: ['/src'],
testMatch: ['**/__tests__/**/*.test.ts'],
collectCoverageFrom: ['src/**/*.ts', '!src/**/*.d.ts', '!src/index.ts'],
coverageThreshold: {
global: { branches: 75, functions: 75, lines: 85, statements: 85 }
}
};