forked from ngneat/spectator
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support passing template in factory (ngneat#299)
- Loading branch information
Dominik Kremer
committed
May 23, 2020
1 parent
5bed723
commit 0f8b8db
Showing
13 changed files
with
227 additions
and
8 deletions.
There are no files selected for viewing
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
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
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
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
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
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
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
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
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
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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { SpectatorPipe, createPipeFactory } from '@ngneat/spectator'; | ||
|
||
import { StatsService } from './stats.service'; | ||
import { AlternatingSumPipe } from './alternating-sum.pipe'; | ||
|
||
describe('AlternatingSumPipe', () => { | ||
let spectator: SpectatorPipe<AlternatingSumPipe>; | ||
const createPipe = createPipeFactory({ | ||
pipe: AlternatingSumPipe, | ||
template: `{{ prop | alternatingSum }}` | ||
}); | ||
|
||
it('should compute the alternating sum of a given list of numbers (prop)', () => { | ||
spectator = createPipe({ | ||
hostProps: { | ||
prop: [1, 2, 3] | ||
} | ||
}); | ||
expect(spectator.element).toHaveText('2'); | ||
}); | ||
|
||
it('should compute the alternating sum of a given list of numbers (template override)', () => { | ||
spectator = createPipe(`{{ [1, 2, 3] | alternatingSum }}`); | ||
expect(spectator.element).toHaveText('2'); | ||
}); | ||
|
||
it('should delegate the computation to the service', () => { | ||
const alternatingSum = () => 42; | ||
const provider = { provide: StatsService, useValue: { alternatingSum } }; | ||
spectator = createPipe({ | ||
hostProps: { | ||
prop: [] | ||
}, | ||
providers: [provider] | ||
}); | ||
expect(spectator.element).toHaveText('42'); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { Pipe, PipeTransform } from '@angular/core'; | ||
|
||
import { StatsService } from './stats.service'; | ||
|
||
@Pipe({ | ||
name: 'alternatingSum' | ||
}) | ||
export class AlternatingSumPipe implements PipeTransform { | ||
constructor(private readonly statsService: StatsService) {} | ||
|
||
public transform(value: number[]): number { | ||
return this.statsService.alternatingSum(value); | ||
} | ||
} |
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
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