-
-
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.
feat(spectator): added directiveProviders to spectator-directive (#236)
- Loading branch information
tamasfoldi
committed
Dec 3, 2019
1 parent
2f18165
commit 4748c5f
Showing
5 changed files
with
54 additions
and
3 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
20 changes: 20 additions & 0 deletions
20
projects/spectator/test/directive-providers.directive.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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { FormBuilder } from '@angular/forms'; | ||
import { createDirectiveFactory, SpectatorDirective } from '@ngneat/spectator'; | ||
|
||
import { DirectiveProviderDirective, directiveProviderToken } from './directive-providers.directive'; | ||
|
||
describe('DirectiveProviderDirective', () => { | ||
let host: SpectatorDirective<DirectiveProviderDirective>; | ||
|
||
const createHost = createDirectiveFactory({ | ||
directive: DirectiveProviderDirective, | ||
directiveProviders: [{ provide: directiveProviderToken, useValue: 'notTest' }], | ||
directiveMocks: [FormBuilder] | ||
}); | ||
|
||
it('should inject the provided value', () => { | ||
host = createHost(`<div directiveProvider>Testing Directive Providers</div>`); | ||
|
||
expect(host.directive.provider).toEqual('notTest'); | ||
}); | ||
}); |
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,12 @@ | ||
import { Directive, Inject, InjectionToken } from '@angular/core'; | ||
import { FormBuilder } from '@angular/forms'; | ||
|
||
export const directiveProviderToken = new InjectionToken('DirectiveProviderToken'); | ||
|
||
@Directive({ | ||
selector: '[directiveProvider]', | ||
providers: [{ provide: directiveProviderToken, useValue: 'test' }] | ||
}) | ||
export class DirectiveProviderDirective { | ||
constructor(@Inject(directiveProviderToken) public provider: string, private fb: FormBuilder) {} | ||
} |