-
-
Notifications
You must be signed in to change notification settings - Fork 187
Open
Description
Is this a regression?
No
Description
When changing the input of a component, setInput correctly handles the assignment of a value to an input signal, but setHostInput assigns the original value directly to the property. I've provided a minimal test file comparing the behaviour of the two functions.
import { Component, input, Pipe, PipeTransform, signal } from '@angular/core';
import {
createComponentFactory,
Spectator,
SpectatorPipe,
} from '@ngneat/spectator';
import { createPipeFactory } from '@ngneat/spectator/jest';
@Component({
template: `
{{ value() | TestPipe }}
`,
standalone: false,
})
class CustomTestComponent {
public value = input<unknown>('');
}
@Pipe({
name: 'TestPipe',
standalone: true,
})
export class TestPipe implements PipeTransform {
public transform<T>(value: T): T {
return value;
}
}
describe('setHostInput', () => {
let spectator: SpectatorPipe<TestPipe, CustomTestComponent>;
const createPipe = createPipeFactory({
pipe: TestPipe,
host: CustomTestComponent,
});
beforeEach(() => {
spectator = createPipe();
});
it('does not change the value of the signal, but instead the property with setHostInput', () => {
const testString = '1234';
let error;
try {
spectator.setHostInput({ value: testString });
} catch (err) {
error = err;
}
expect(error).toMatchObject(new TypeError('ctx.value is not a function'));
error = undefined;
try {
spectator.setHostInput({ value: signal(testString) });
expect(spectator.element).toHaveExactTrimmedText(testString);
} catch (err) {
error = err;
}
expect(error).toBeUndefined();
});
});
@Component({
template: `
{{ value() }}
`,
standalone: false,
})
class CustomTest2Component {
public value = input<unknown>('');
}
describe('setInput', () => {
let spectator: Spectator<CustomTest2Component>;
const createComponent = createComponentFactory({
component: CustomTest2Component,
});
it('does change the value of the signal with setInput', () => {
spectator = createComponent();
const testString = '1234';
expect(spectator.component.value()).toBe('');
let error;
try {
spectator.setInput({ value: testString });
expect(spectator.element).toHaveExactTrimmedText(testString);
} catch (err) {
error = err;
}
expect(error).toBeUndefined();
});
});
Please provide a link to a minimal reproduction of the bug
No response
Please provide the exception or error you saw
When assigning the value without wrapping it as a signal in setHostInput:
`TypeError: ctx.value is not a function`
Please provide the environment you discovered this bug in
@angular/core: npm:20.0.6
@ngneat/spectator: npm:20.0.0
Anything else?
No response
Do you want to create a pull request?
No
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels