Rules that enforce proper usage of Jasmine's expect() functionality and matchers to ensure reliable test assertions.
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' });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);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();
});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] // DEPRECATEDAll expectation rules support standard ESLint severity levels:
0 or "off" - Disable the rule1 or "warn" - Enable as warning2 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// 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);
});