CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-eslint-plugin-jasmine

ESLint plugin providing 23 linting rules specifically designed for Jasmine testing framework to enforce best practices and catch common mistakes

Pending
Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

SecuritybySnyk

Pending

The risk profile of this skill

Overview
Eval results
Files

test-structure-rules.mddocs/

Test Structure Rules

Rules that enforce proper test organization and prevent common structural issues that can lead to unreliable or confusing test suites.

Capabilities

no-focused-tests

Prevents accidental commits of focused tests (fdescribe, fit, etc.) that would cause other tests to be skipped in CI/CD pipelines.

/**
 * Rule: no-focused-tests
 * Disallows focused test functions that skip other tests
 * @config [0|1|2] - Rule severity level
 * Detects: fdescribe, ddescribe, fit, iit
 */
'jasmine/no-focused-tests': [0|1|2]

Examples:

// ❌ Bad - focused tests
fdescribe('User service', function() { /* ... */ });
fit('should validate input', function() { /* ... */ });
ddescribe('Legacy syntax', function() { /* ... */ });
iit('Legacy focused test', function() { /* ... */ });

// ✅ Good - normal tests
describe('User service', function() { /* ... */ });
it('should validate input', function() { /* ... */ });

no-disabled-tests

Prevents accumulation of disabled tests that can indicate incomplete development or forgotten test maintenance.

/**
 * Rule: no-disabled-tests
 * Disallows disabled test functions
 * @config [0|1|2] - Rule severity level
 * Detects: xdescribe, xit, pending tests
 */
'jasmine/no-disabled-tests': [0|1|2]

Examples:

// ❌ Bad - disabled tests
xdescribe('User service', function() { /* ... */ });
xit('should validate input', function() { /* ... */ });
pending('Not implemented yet');

// ✅ Good - active tests
describe('User service', function() { /* ... */ });
it('should validate input', function() { /* ... */ });

no-pending-tests

Specifically targets Jasmine's pending() function calls that mark tests as incomplete.

/**
 * Rule: no-pending-tests
 * Disallows pending() function calls in tests
 * @config [0|1|2] - Rule severity level
 */
'jasmine/no-pending-tests': [0|1|2]

Examples:

// ❌ Bad - pending test
it('should implement feature', function() {
  pending('Feature not implemented yet');
});

// ✅ Good - complete test or skip if needed
it('should implement feature', function() {
  const result = implementFeature();
  expect(result).toBeDefined();
});

no-suite-dupes

Prevents duplicate suite (describe block) names that can cause confusion when reading test output.

/**
 * Rule: no-suite-dupes
 * Disallows duplicate suite names
 * @config [0|1|2, mode] - Rule severity and detection mode
 * @param mode 'block' | 'branch' - Detection scope
 * @default mode 'block'
 */
'jasmine/no-suite-dupes': [0|1|2, 'block' | 'branch']

Configuration:

  • 'block' - Only check within the same nesting level
  • 'branch' - Check full branch path including parent suites

Examples:

// ❌ Bad - duplicate suite names (block mode)
describe('User service', function() { /* ... */ });
describe('User service', function() { /* ... */ }); // Duplicate!

// ❌ Bad - duplicate branch paths (branch mode)
describe('API', function() {
  describe('Users', function() { /* ... */ });
});
describe('API', function() {
  describe('Users', function() { /* ... */ }); // Duplicate branch!
});

// ✅ Good - unique suite names
describe('User service', function() { /* ... */ });
describe('User validation', function() { /* ... */ });

no-spec-dupes

Prevents duplicate spec (it block) names that can cause confusion in test reports.

/**
 * Rule: no-spec-dupes
 * Disallows duplicate spec names
 * @config [0|1|2, mode] - Rule severity and detection mode
 * @param mode 'block' | 'branch' - Detection scope
 * @default mode 'block'
 */
'jasmine/no-spec-dupes': [0|1|2, 'block' | 'branch']

Configuration:

  • 'block' - Only check within the same describe block
  • 'branch' - Check full branch path including parent describe blocks

Examples:

// ❌ Bad - duplicate spec names
describe('Calculator', function() {
  it('should add numbers', function() { /* ... */ });
  it('should add numbers', function() { /* ... */ }); // Duplicate!
});

// ❌ Bad - duplicate in branch mode
describe('Math', function() {
  describe('Addition', function() {
    it('should handle positive numbers', function() { /* ... */ });
  });
  describe('Subtraction', function() {
    it('should handle positive numbers', function() { /* ... */ }); // Duplicate branch!
  });
});

// ✅ Good - unique spec names
describe('Calculator', function() {
  it('should add positive numbers', function() { /* ... */ });
  it('should add negative numbers', function() { /* ... */ });
});

Rule Configuration

All test structure rules support standard ESLint severity levels:

  • 0 or "off" - Disable the rule
  • 1 or "warn" - Enable as warning
  • 2 or "error" - Enable as error (fails lint)

Recommended Settings:

rules:
  jasmine/no-focused-tests: 2      # Error - critical for CI/CD
  jasmine/no-disabled-tests: 1     # Warning - should be reviewed
  jasmine/no-pending-tests: 1      # Warning - should be completed
  jasmine/no-suite-dupes: 1        # Warning - can cause confusion
  jasmine/no-spec-dupes: 1         # Warning - can cause confusion

Common Patterns

Organizing Test Suites

// Good test organization
describe('UserService', function() {
  describe('constructor', function() {
    it('should create instance with default options', function() { /* ... */ });
    it('should create instance with custom options', function() { /* ... */ });
  });
  
  describe('validateUser', function() {
    it('should return true for valid user', function() { /* ... */ });
    it('should return false for invalid email', function() { /* ... */ });
    it('should return false for missing name', function() { /* ... */ });
  });
  
  describe('saveUser', function() {
    it('should save valid user to database', function() { /* ... */ });
    it('should throw error for invalid user', function() { /* ... */ });
  });
});

Avoiding Common Issues

// ❌ Avoid - makes other tests invisible
fdescribe('Only this suite will run', function() { /* ... */ });

// ❌ Avoid - accumulating disabled tests
xdescribe('Broken tests', function() { /* ... */ });

// ✅ Good - fix or remove broken tests
describe('Fixed tests', function() {
  it('should work correctly', function() { /* ... */ });
});

docs

code-organization-rules.md

code-style-rules.md

expectation-rules.md

index.md

jasmine-matcher-rules.md

promise-rules.md

spy-rules.md

test-structure-rules.md

tile.json