-
-
Notifications
You must be signed in to change notification settings - Fork 177
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
134 additions
and
60 deletions.
There are no files selected for viewing
97 changes: 67 additions & 30 deletions
97
projects/spectator/jest/test/set-input-alias-names.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,72 @@ | ||
import { Component, Input } from '@angular/core'; | ||
import { Component, Input, input } from '@angular/core'; | ||
import { createComponentFactory } from '@ngneat/spectator/jest'; | ||
|
||
describe('SetInputAliasNames', () => { | ||
@Component({ | ||
selector: 'app-root', | ||
template: ` | ||
<div data-test="set-input--name">{{ name }}</div> | ||
<div data-test="set-input--age">{{ numOfYears }}</div> | ||
`, | ||
standalone: true, | ||
}) | ||
class DummyComponent { | ||
@Input('userName') name!: string; | ||
@Input({ alias: 'age' }) numOfYears!: number; | ||
} | ||
|
||
const createComponent = createComponentFactory(DummyComponent); | ||
|
||
it('setInput 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'); | ||
spectator.setInput('age', '123'); | ||
|
||
// Assert | ||
expect(nameElement.innerHTML).toBe('John'); | ||
expect(ageElement.innerHTML).toBe('123'); | ||
describe('input decorators', () => { | ||
@Component({ | ||
selector: 'app-root', | ||
template: ` | ||
<div data-test="set-input--name">{{ name }}</div> | ||
<div data-test="set-input--age">{{ numOfYears }}</div> | ||
`, | ||
standalone: true, | ||
}) | ||
class DummyComponent { | ||
@Input('userName') name!: string; | ||
@Input({ alias: 'age' }) numOfYears!: number; | ||
} | ||
|
||
const createComponent = createComponentFactory(DummyComponent); | ||
|
||
it('setInput 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'); | ||
spectator.setInput('age', '123'); | ||
|
||
// Assert | ||
expect(nameElement.innerHTML).toBe('John'); | ||
expect(ageElement.innerHTML).toBe('123'); | ||
}); | ||
}); | ||
|
||
describe('signal inputs', () => { | ||
@Component({ | ||
selector: 'app-root', | ||
template: ` | ||
<div data-test="set-input--name">{{ name() }}</div> | ||
<div data-test="set-input--age">{{ numOfYears() }}</div> | ||
`, | ||
standalone: true, | ||
}) | ||
class DummyComponent { | ||
name = input.required({ alias: 'userName' }); | ||
numOfYears = input(0, { alias: 'age' }); | ||
} | ||
|
||
const createComponent = createComponentFactory(DummyComponent); | ||
|
||
it('setInput 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'); | ||
spectator.setInput('age', '123'); | ||
|
||
// Assert | ||
expect(nameElement.innerHTML).toBe('John'); | ||
expect(ageElement.innerHTML).toBe('123'); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,72 @@ | ||
import { Component, Input } from '@angular/core'; | ||
import { Component, Input, input } from '@angular/core'; | ||
import { createComponentFactory } from '@ngneat/spectator'; | ||
|
||
describe('SetInputAliasNames', () => { | ||
@Component({ | ||
selector: 'app-root', | ||
template: ` | ||
<div data-test="set-input--name">{{ name }}</div> | ||
<div data-test="set-input--age">{{ numOfYears }}</div> | ||
`, | ||
standalone: true, | ||
}) | ||
class DummyComponent { | ||
@Input('userName') name!: string; | ||
@Input({ alias: 'age' }) numOfYears!: number; | ||
} | ||
|
||
const createComponent = createComponentFactory(DummyComponent); | ||
|
||
it('setInput 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'); | ||
spectator.setInput('age', '123'); | ||
|
||
// Assert | ||
expect(nameElement.innerHTML).toBe('John'); | ||
expect(ageElement.innerHTML).toBe('123'); | ||
describe('input decorators', () => { | ||
@Component({ | ||
selector: 'app-root', | ||
template: ` | ||
<div data-test="set-input--name">{{ name }}</div> | ||
<div data-test="set-input--age">{{ numOfYears }}</div> | ||
`, | ||
standalone: true, | ||
}) | ||
class DummyComponent { | ||
@Input('userName') name!: string; | ||
@Input({ alias: 'age' }) numOfYears!: number; | ||
} | ||
|
||
const createComponent = createComponentFactory(DummyComponent); | ||
|
||
it('setInput 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'); | ||
spectator.setInput('age', '123'); | ||
|
||
// Assert | ||
expect(nameElement.innerHTML).toBe('John'); | ||
expect(ageElement.innerHTML).toBe('123'); | ||
}); | ||
}); | ||
|
||
describe('signal inputs', () => { | ||
@Component({ | ||
selector: 'app-root', | ||
template: ` | ||
<div data-test="set-input--name">{{ name() }}</div> | ||
<div data-test="set-input--age">{{ numOfYears() }}</div> | ||
`, | ||
standalone: true, | ||
}) | ||
class DummyComponent { | ||
name = input.required({ alias: 'userName' }); | ||
numOfYears = input(0, { alias: 'age' }); | ||
} | ||
|
||
const createComponent = createComponentFactory(DummyComponent); | ||
|
||
it('setInput 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'); | ||
spectator.setInput('age', '123'); | ||
|
||
// Assert | ||
expect(nameElement.innerHTML).toBe('John'); | ||
expect(ageElement.innerHTML).toBe('123'); | ||
}); | ||
}); | ||
}); |