For the complete documentation index, see llms.txt. This page is also available as Markdown.

Testing Custom Value Converters and Binding Behaviors

Value converters and binding behaviors are powerful tools in Aurelia for transforming and modifying data during binding. Testing these requires specific strategies to ensure their reliability and correct functionality.

Value Converter Testing

What are Value Converters?

Value converters are used to transform data between the view and view-model:

  • Convert data formatting

  • Transform data representations

  • Perform custom data manipulations

Basic Value Converter Example and Test

// Value Converter
export class UppercaseValueConverter {
  toView(value: string): string {
    return value ? value.toUpperCase() : '';
  }

  fromView(value: string): string {
    return value ? value.toLowerCase() : '';
  }
}

// Testing Value Converter
describe('UppercaseValueConverter', () => {
  let converter: UppercaseValueConverter;

  beforeEach(() => {
    converter = new UppercaseValueConverter();
  });

  it('should convert string to uppercase', () => {
    expect(converter.toView('hello')).toBe('HELLO');
    expect(converter.toView('')).toBe('');
    expect(converter.toView(null)).toBe('');
  });

  it('should convert string to lowercase from view', () => {
    expect(converter.fromView('HELLO')).toBe('hello');
    expect(converter.fromView('')).toBe('');
    expect(converter.fromView(null)).toBe('');
  });
});

Complex Value Converter Testing

Binding Behavior Testing

What are Binding Behaviors?

Binding behaviors modify how binding works:

  • Debounce user input

  • Trigger specific binding actions

  • Modify binding performance

Simple Binding Behavior Example

Component Integration Testing

Last updated

Was this helpful?