-
-
Notifications
You must be signed in to change notification settings - Fork 178
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: override providers for createComponentFactory
- Loading branch information
1 parent
9fdd98f
commit 570af04
Showing
2 changed files
with
77 additions
and
19 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { createComponentFactory, Spectator } from '@ngneat/spectator'; | ||
import { Component, InjectionToken } from '@angular/core'; | ||
|
||
@Component({ | ||
selector: 'lib-test', | ||
template: '<div>test</div>' | ||
}) | ||
class TestComponent {} | ||
|
||
class StateMock {} | ||
|
||
class AnotherStateMock {} | ||
|
||
export const STATE = new InjectionToken<any>('Angular State'); | ||
|
||
describe('Override providers', () => { | ||
let spectator: Spectator<TestComponent>; | ||
|
||
const createComponent = createComponentFactory({ | ||
component: TestComponent, | ||
providers: [{ provide: STATE, useClass: AnotherStateMock }] | ||
}); | ||
|
||
beforeEach(() => (spectator = createComponent())); | ||
|
||
it('should create', () => { | ||
expect(spectator).toBeTruthy(); | ||
}); | ||
|
||
it('should get the correct instance of STATE', () => { | ||
const service = spectator.inject(STATE); | ||
|
||
expect(service instanceof AnotherStateMock).toBeTrue(); | ||
}); | ||
|
||
it('should get the mocked instance of STATE injection token', () => { | ||
spectator = createComponent({ providers: [{ provide: STATE, useClass: StateMock }] }); | ||
|
||
const service = spectator.inject(STATE); | ||
|
||
expect(service instanceof StateMock).toBeTrue(); | ||
}); | ||
}); |