forked from help-me-mom/ng-mocks
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: generic type constraint for ngMocks.stub tedious to write
closes #166
- Loading branch information
Showing
4 changed files
with
53 additions
and
47 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// tslint:enable:no-any no-unsafe-any | ||
|
||
import { MockService, ngMocks } from 'ng-mocks'; | ||
import { Observable, Subject } from 'rxjs'; | ||
|
||
// fix to support both jasmine and jest in the test | ||
declare let jest: { fn(): () => any }; | ||
declare let jasmine: { createSpy(): () => any }; | ||
|
||
class MyService { | ||
public readonly onErrorSet$: Observable<string>; | ||
public readonly onSuccessSet$: Observable<string>; | ||
public readonly onWarningSet$: Observable<string>; | ||
|
||
protected value = 'MyService'; | ||
|
||
public stringMethod(): string { | ||
return this.value; | ||
} | ||
|
||
public voidMethod(sum: string): void { | ||
this.value = `${this.value}${sum}`; | ||
} | ||
} | ||
|
||
describe('issue-166', () => { | ||
it('accepts spies', () => { | ||
const spy = typeof jest !== 'undefined' ? jest.fn() : jasmine.createSpy(); | ||
const stub = ngMocks.stub(MockService(MyService), { | ||
fakeMethod: () => 123, | ||
onErrorSet$: new Subject<string>(), | ||
onWarningSet$: new Subject<string>(), | ||
stringMethod: spy, | ||
voidMethod: spy, | ||
}); | ||
ngMocks.stub(stub, 'onSuccessSet$', 'get'); | ||
|
||
expect(stub).toBeDefined(); | ||
}); | ||
}); |