Skip to content

Commit

Permalink
fix(spectator): setInput with object parameter for alias names (#692)
Browse files Browse the repository at this point in the history
Co-authored-by: Nicolas CROZE <nicolas.croze@4dconcept.fr>
  • Loading branch information
kheos31 and ncroze-4d authored Jan 28, 2025
1 parent aae7717 commit 25afec2
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 0 deletions.
38 changes: 38 additions & 0 deletions projects/spectator/jest/test/set-input-alias-names.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,24 @@ describe('SetInputAliasNames', () => {
expect(nameElement.innerHTML).toBe('John');
expect(ageElement.innerHTML).toBe('123');
});

it('setInput with object should respect the alias names', () => {
// Arrange
const spectator = createComponent();

const nameElement = spectator.query('[data-test="set-input--name"]')!;
const ageElement = spectator.query('[data-test="set-input--age"]')!;

// Act
spectator.setInput({
userName: 'John',
age: '123',
});

// Assert
expect(nameElement.innerHTML).toBe('John');
expect(ageElement.innerHTML).toBe('123');
});
});

describe('signal inputs', () => {
Expand Down Expand Up @@ -68,5 +86,25 @@ describe('SetInputAliasNames', () => {
expect(nameElement.innerHTML).toBe('John');
expect(ageElement.innerHTML).toBe('123');
});

it('setInput with object should respect the alias names', () => {
// Arrange
const spectator = createComponent({
detectChanges: false,
});

const nameElement = spectator.query('[data-test="set-input--name"]')!;
const ageElement = spectator.query('[data-test="set-input--age"]')!;

// Act
spectator.setInput({
userName: 'John',
age: '123',
});

// Assert
expect(nameElement.innerHTML).toBe('John');
expect(ageElement.innerHTML).toBe('123');
});
});
});
1 change: 1 addition & 0 deletions projects/spectator/src/lib/spectator/spectator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export class Spectator<C> extends DomSpectator<C> {
}

public setInput<K extends keyof C>(input: InferInputSignals<C>): void;
public setInput(input: { [inputName: string]: unknown }): void;
public setInput<K extends keyof C>(input: K, inputValue: InferInputSignal<C[K]>): void;
public setInput(input: string, inputValue: unknown): void;
public setInput(input: any, value?: any): void {
Expand Down
38 changes: 38 additions & 0 deletions projects/spectator/test/set-input-alias-names.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,24 @@ describe('SetInputAliasNames', () => {
expect(nameElement.innerHTML).toBe('John');
expect(ageElement.innerHTML).toBe('123');
});

it('setInput with object should respect the alias names', () => {
// Arrange
const spectator = createComponent();

const nameElement = spectator.query('[data-test="set-input--name"]')!;
const ageElement = spectator.query('[data-test="set-input--age"]')!;

// Act
spectator.setInput({
userName: 'John',
age: '123',
});

// Assert
expect(nameElement.innerHTML).toBe('John');
expect(ageElement.innerHTML).toBe('123');
});
});

describe('signal inputs', () => {
Expand Down Expand Up @@ -68,5 +86,25 @@ describe('SetInputAliasNames', () => {
expect(nameElement.innerHTML).toBe('John');
expect(ageElement.innerHTML).toBe('123');
});

it('setInput with object should respect the alias names', () => {
// Arrange
const spectator = createComponent({
detectChanges: false,
});

const nameElement = spectator.query('[data-test="set-input--name"]')!;
const ageElement = spectator.query('[data-test="set-input--age"]')!;

// Act
spectator.setInput({
userName: 'John',
age: '123',
});

// Assert
expect(nameElement.innerHTML).toBe('John');
expect(ageElement.innerHTML).toBe('123');
});
});
});
38 changes: 38 additions & 0 deletions projects/spectator/vitest/test/set-input-alias-names.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,24 @@ describe('SetInputAliasNames', () => {
expect(nameElement.innerHTML).toBe('John');
expect(ageElement.innerHTML).toBe('123');
});

it('setInput with object should respect the alias names', () => {
// Arrange
const spectator = createComponent();

const nameElement = spectator.query('[data-test="set-input--name"]')!;
const ageElement = spectator.query('[data-test="set-input--age"]')!;

// Act
spectator.setInput({
userName: 'John',
age: '123',
});

// Assert
expect(nameElement.innerHTML).toBe('John');
expect(ageElement.innerHTML).toBe('123');
});
});

describe('signal inputs', () => {
Expand Down Expand Up @@ -68,5 +86,25 @@ describe('SetInputAliasNames', () => {
expect(nameElement.innerHTML).toBe('John');
expect(ageElement.innerHTML).toBe('123');
});

it('setInput with object should respect the alias names', () => {
// Arrange
const spectator = createComponent({
detectChanges: false,
});

const nameElement = spectator.query('[data-test="set-input--name"]')!;
const ageElement = spectator.query('[data-test="set-input--age"]')!;

// Act
spectator.setInput({
userName: 'John',
age: '123',
});

// Assert
expect(nameElement.innerHTML).toBe('John');
expect(ageElement.innerHTML).toBe('123');
});
});
});

0 comments on commit 25afec2

Please sign in to comment.