Im testing @Input property from another component that has default value
import { Component, Input } from '@angular/core'
export type Variant = 'primary' | 'secondary'
@Component({
selector: 'my-button',
standalone: true,
template: `
<button>
<span>
<ng-content></ng-content>
</span>
</button>
`
})
export class MyButtonComponent {
@Input() variant: Variant = 'primary'
}
import { Component } from '@angular/core';
import { TestBed, } from '@angular/core/testing';
import { MyButtonComponent } from './button.component';
import { By } from '@angular/platform-browser'
describe('MyButton', () => {
it('should have default value for variant', () => {
@Component({
template: `
<my-button>Hello</my-button>
`,
imports: [ MyButtonComponent ]
})
class TestComponent {}
const fixture = TestBed.createComponent(TestComponent)
const button = fixture.debugElement.query(By.css('my-button')).nativeElement as MyButtonComponent
/// since component property variant has default with primary
/// this should be passed
expect(button.variant).toEqual('primary')
})
})