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

expectation-rules.mddocs/

Expectation Rules

Rules that enforce proper usage of Jasmine's expect() functionality and matchers to ensure reliable test assertions.

Capabilities

expect-matcher

Enforces that every expect() call has a corresponding matcher call to prevent incomplete assertions.

/**
 * Rule: expect-matcher
 * Ensures expect() calls are followed by matcher methods
 * @config [0|1|2] - Rule severity level
 */
'jasmine/expect-matcher': [0|1|2]

Examples:

// ❌ Bad - expect without matcher
expect(value);

// ✅ Good - expect with matcher
expect(value).toBe(true);
expect(result).toEqual({ status: 'success' });

expect-single-argument

Enforces that expect() calls take exactly one argument to prevent confusion and ensure clear test assertions.

/**
 * Rule: expect-single-argument
 * Ensures expect() receives exactly one argument
 * @config [0|1|2] - Rule severity level
 */
'jasmine/expect-single-argument': [0|1|2]

Examples:

// ❌ Bad - multiple arguments
expect(a, b).toBe(true);

// ❌ Bad - no arguments
expect().toBe(true);

// ✅ Good - single argument
expect(value).toBe(true);
expect(calculateSum(2, 3)).toEqual(5);

missing-expect

Enforces that test specs contain at least one expectation to ensure tests actually validate behavior.

/**
 * Rule: missing-expect
 * Ensures test specs contain expectation calls
 * @config [0|1|2, ...expectationFunctions] - Rule severity and custom expectation function names
 * @default expectationFunctions ['expect()', 'expectAsync()']
 */
'jasmine/missing-expect': [0|1|2, 'expect()', 'expectAsync()']

Configuration Examples:

// Default configuration
'jasmine/missing-expect': 1

// Custom expectation functions
'jasmine/missing-expect': [1, 'expect()', 'expectAsync()', 'customExpect()']

Examples:

// ❌ Bad - no expectations
it('should do something', function() {
  setupData();
  performAction();
  // Missing expectation
});

// ✅ Good - has expectation
it('should calculate correctly', function() {
  const result = calculate(2, 3);
  expect(result).toBe(5);
});

// ✅ Good - async expectation
it('should handle async operations', async function() {
  const data = await fetchData();
  expectAsync(processData(data)).toBeResolved();
});

valid-expect (Deprecated)

Legacy rule for enforcing valid expect usage patterns. This rule is deprecated and should not be used in new configurations.

/**
 * Rule: valid-expect (DEPRECATED)
 * Legacy rule for expect validation - use other expectation rules instead
 * @config [0|1|2] - Rule severity level
 * @deprecated Use expect-matcher and expect-single-argument instead
 */
'jasmine/valid-expect': [0|1|2] // DEPRECATED

Rule Configuration

All expectation 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/expect-matcher: 1
  jasmine/expect-single-argument: 1
  jasmine/missing-expect: 0  # Often too strict for setup/teardown tests
  jasmine/valid-expect: 0    # Deprecated

Common Patterns

Setting Up Expectations

// Multiple related expectations
it('should validate user data', function() {
  const user = createUser({ name: 'John', age: 30 });
  
  expect(user.name).toBe('John');
  expect(user.age).toBe(30);
  expect(user.isValid()).toBe(true);
});

// Async expectations
it('should handle promises', async function() {
  const promise = fetchUserData(123);
  
  await expectAsync(promise).toBeResolved();
  const user = await promise;
  expect(user.id).toBe(123);
});

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