Skip to content

Commit aad994b

Browse files
committed
fix(spectator): setInput with object parameter for alias names
1 parent aae7717 commit aad994b

File tree

4 files changed

+115
-0
lines changed

4 files changed

+115
-0
lines changed

projects/spectator/jest/test/set-input-alias-names.spec.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,24 @@ describe('SetInputAliasNames', () => {
3333
expect(nameElement.innerHTML).toBe('John');
3434
expect(ageElement.innerHTML).toBe('123');
3535
});
36+
37+
it('setInput with object should respect the alias names', () => {
38+
// Arrange
39+
const spectator = createComponent();
40+
41+
const nameElement = spectator.query('[data-test="set-input--name"]')!;
42+
const ageElement = spectator.query('[data-test="set-input--age"]')!;
43+
44+
// Act
45+
spectator.setInput({
46+
userName: 'John',
47+
age: '123',
48+
});
49+
50+
// Assert
51+
expect(nameElement.innerHTML).toBe('John');
52+
expect(ageElement.innerHTML).toBe('123');
53+
});
3654
});
3755

3856
describe('signal inputs', () => {
@@ -68,5 +86,25 @@ describe('SetInputAliasNames', () => {
6886
expect(nameElement.innerHTML).toBe('John');
6987
expect(ageElement.innerHTML).toBe('123');
7088
});
89+
90+
it('setInput with object should respect the alias names', () => {
91+
// Arrange
92+
const spectator = createComponent({
93+
detectChanges: false,
94+
});
95+
96+
const nameElement = spectator.query('[data-test="set-input--name"]')!;
97+
const ageElement = spectator.query('[data-test="set-input--age"]')!;
98+
99+
// Act
100+
spectator.setInput({
101+
userName: 'John',
102+
age: '123',
103+
});
104+
105+
// Assert
106+
expect(nameElement.innerHTML).toBe('John');
107+
expect(ageElement.innerHTML).toBe('123');
108+
});
71109
});
72110
});

projects/spectator/src/lib/spectator/spectator.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ export class Spectator<C> extends DomSpectator<C> {
4141
}
4242

4343
public setInput<K extends keyof C>(input: InferInputSignals<C>): void;
44+
public setInput(input: { [inputName: string]: unknown }): void;
4445
public setInput<K extends keyof C>(input: K, inputValue: InferInputSignal<C[K]>): void;
4546
public setInput(input: string, inputValue: unknown): void;
4647
public setInput(input: any, value?: any): void {

projects/spectator/test/set-input-alias-names.spec.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,24 @@ describe('SetInputAliasNames', () => {
3333
expect(nameElement.innerHTML).toBe('John');
3434
expect(ageElement.innerHTML).toBe('123');
3535
});
36+
37+
it('setInput with object should respect the alias names', () => {
38+
// Arrange
39+
const spectator = createComponent();
40+
41+
const nameElement = spectator.query('[data-test="set-input--name"]')!;
42+
const ageElement = spectator.query('[data-test="set-input--age"]')!;
43+
44+
// Act
45+
spectator.setInput({
46+
userName: 'John',
47+
age: '123',
48+
});
49+
50+
// Assert
51+
expect(nameElement.innerHTML).toBe('John');
52+
expect(ageElement.innerHTML).toBe('123');
53+
});
3654
});
3755

3856
describe('signal inputs', () => {
@@ -68,5 +86,25 @@ describe('SetInputAliasNames', () => {
6886
expect(nameElement.innerHTML).toBe('John');
6987
expect(ageElement.innerHTML).toBe('123');
7088
});
89+
90+
it('setInput with object should respect the alias names', () => {
91+
// Arrange
92+
const spectator = createComponent({
93+
detectChanges: false,
94+
});
95+
96+
const nameElement = spectator.query('[data-test="set-input--name"]')!;
97+
const ageElement = spectator.query('[data-test="set-input--age"]')!;
98+
99+
// Act
100+
spectator.setInput({
101+
userName: 'John',
102+
age: '123',
103+
});
104+
105+
// Assert
106+
expect(nameElement.innerHTML).toBe('John');
107+
expect(ageElement.innerHTML).toBe('123');
108+
});
71109
});
72110
});

projects/spectator/vitest/test/set-input-alias-names.spec.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,24 @@ describe('SetInputAliasNames', () => {
3333
expect(nameElement.innerHTML).toBe('John');
3434
expect(ageElement.innerHTML).toBe('123');
3535
});
36+
37+
it('setInput with object should respect the alias names', () => {
38+
// Arrange
39+
const spectator = createComponent();
40+
41+
const nameElement = spectator.query('[data-test="set-input--name"]')!;
42+
const ageElement = spectator.query('[data-test="set-input--age"]')!;
43+
44+
// Act
45+
spectator.setInput({
46+
userName: 'John',
47+
age: '123',
48+
});
49+
50+
// Assert
51+
expect(nameElement.innerHTML).toBe('John');
52+
expect(ageElement.innerHTML).toBe('123');
53+
});
3654
});
3755

3856
describe('signal inputs', () => {
@@ -68,5 +86,25 @@ describe('SetInputAliasNames', () => {
6886
expect(nameElement.innerHTML).toBe('John');
6987
expect(ageElement.innerHTML).toBe('123');
7088
});
89+
90+
it('setInput with object should respect the alias names', () => {
91+
// Arrange
92+
const spectator = createComponent({
93+
detectChanges: false,
94+
});
95+
96+
const nameElement = spectator.query('[data-test="set-input--name"]')!;
97+
const ageElement = spectator.query('[data-test="set-input--age"]')!;
98+
99+
// Act
100+
spectator.setInput({
101+
userName: 'John',
102+
age: '123',
103+
});
104+
105+
// Assert
106+
expect(nameElement.innerHTML).toBe('John');
107+
expect(ageElement.innerHTML).toBe('123');
108+
});
71109
});
72110
});

0 commit comments

Comments
 (0)