-
-
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.
feat(genericDefault): add support for default generics on declaration…
… and extensions (#126) * add support for default generics on declaration and extensions * reduce amount of nested if statements * reduce amount of if statement in generic extensions
- Loading branch information
Showing
5 changed files
with
101 additions
and
39 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,49 @@ | ||
import { createMock } from 'ts-auto-mock'; | ||
|
||
describe('generic default', () => { | ||
it('should assign the default value when not provided', () => { | ||
interface B<P> { | ||
prop: P; | ||
} | ||
|
||
interface A<P = { a: string }> extends B<P> { | ||
} | ||
|
||
const mock: A = createMock<A>(); | ||
|
||
expect(mock.prop.a).toEqual(''); | ||
}); | ||
|
||
it('should assign the default value of the second argument when not provided', () => { | ||
interface B<P, S> { | ||
prop: P; | ||
prop2: S; | ||
} | ||
|
||
interface A<P = { a: string }, S = number> extends B<P, S> { | ||
} | ||
|
||
const mock: A<{ a: number }> = createMock<A<{ a: number }>>(); | ||
|
||
expect(mock.prop.a).toEqual(0); | ||
expect(mock.prop2).toEqual(0); | ||
}); | ||
|
||
it('should assign the default value for extension with default value', () => { | ||
interface C<T> { | ||
cProp: T; | ||
} | ||
|
||
interface B<P = { a: string }> extends C<P> { | ||
bProp: P; | ||
} | ||
|
||
interface A extends B { | ||
} | ||
|
||
const mock: A = createMock<A>(); | ||
|
||
expect(mock.cProp.a).toEqual(''); | ||
expect(mock.bProp.a).toEqual(''); | ||
}); | ||
}); |
File renamed without changes.