-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(registerMock): allow to use mocks defined in variables (#330)
* fix(registerMock): allow to use mocks defined in variables * test(registerMock): fix wrong test description Co-authored-by: Vittorio Guerriero <[email protected]>
- Loading branch information
Showing
3 changed files
with
58 additions
and
36 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { createMock, registerMock } from 'ts-auto-mock'; | ||
|
||
describe('registerMock using vars from the scope', () => { | ||
it('should override standard behaviour of mock creation using values from the scope', () => { | ||
interface APropInterface { | ||
internalProp: string; | ||
call: () => APropInterface; | ||
} | ||
|
||
interface AParentInterface { | ||
prop: APropInterface; | ||
} | ||
|
||
const propInstance: APropInterface = { internalProp: 'whaaat', call: () => propInstance }; | ||
|
||
registerMock<APropInterface>(() => propInstance); | ||
|
||
const mock: AParentInterface = createMock<AParentInterface>(); | ||
|
||
expect(mock.prop).toBe(propInstance); | ||
expect(mock.prop.call()).toBe(propInstance); | ||
}); | ||
|
||
it('should override standard behaviour of mock creation using values from createMock', () => { | ||
interface APropInterface { | ||
internalProp: string; | ||
call: () => APropInterface; | ||
} | ||
|
||
interface AParentInterface { | ||
prop: APropInterface; | ||
} | ||
|
||
const propInstance: APropInterface = createMock<APropInterface>(); | ||
|
||
registerMock<APropInterface>(() => propInstance); | ||
|
||
const mock: AParentInterface = createMock<AParentInterface>(); | ||
|
||
expect(mock.prop).toBe(propInstance); | ||
expect(mock.prop.call()).toBe(propInstance); | ||
}); | ||
}); |