This repository has been archived by the owner on May 27, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
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
1 parent
39a93f0
commit 58421b6
Showing
5 changed files
with
119 additions
and
2 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,3 @@ | ||
{ | ||
"ngPackage": {} | ||
} |
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,29 @@ | ||
import { of, Subject } from 'rxjs'; | ||
import { Store } from '@ngxs/store'; | ||
import { TestBed } from '@angular/core/testing'; | ||
|
||
class NgxsJestHelper { | ||
private static mockedSelector: { key: any; value: Subject<any> }[] = []; | ||
|
||
static mockSelect<T>(selectorFn: (state: any) => T): Subject<T> { | ||
const store: Store = TestBed.get(Store); | ||
if (!jest.isMockFunction(store.select)) { | ||
jest.spyOn(store, 'select').mockImplementation((selector) => { | ||
const match = NgxsJestHelper.mockedSelector.find((s) => s.key === selector); | ||
if (match) { | ||
return match.value; | ||
} | ||
return of(); | ||
}); | ||
} | ||
|
||
const subject = new Subject<T>(); | ||
NgxsJestHelper.mockedSelector = [ | ||
...NgxsJestHelper.mockedSelector.filter((s) => s.key !== selectorFn), | ||
{ key: selectorFn, value: subject } | ||
]; | ||
return subject; | ||
} | ||
} | ||
|
||
export const mockSelect = NgxsJestHelper.mockSelect; |
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 @@ | ||
export { mockSelect } from './jest-helpers'; |
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