-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: option to specify a fallback resolve value
- Loading branch information
1 parent
1665921
commit 5b8c059
Showing
4 changed files
with
63 additions
and
1 deletion.
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,44 @@ | ||
import base from '../..'; | ||
|
||
const setup = () => { | ||
const jpex = base.extend(); | ||
|
||
return { | ||
jpex, | ||
}; | ||
}; | ||
|
||
test('if factory exists, it should be resolved', () => { | ||
const { jpex } = setup(); | ||
type Foo = string; | ||
jpex.constant<Foo>('foo'); | ||
|
||
const result = jpex.resolve<Foo>({ default: 'bar' }); | ||
|
||
expect(result).toBe('foo'); | ||
}); | ||
|
||
test('if factory does not exist, it should return the default', () => { | ||
const { jpex } = setup(); | ||
type Foo = string; | ||
|
||
const result = jpex.resolve<Foo>({ default: 'bar' }); | ||
|
||
expect(result).toBe('bar'); | ||
}); | ||
|
||
test('if factory does not exist and default not provided, it should throw an error', () => { | ||
const { jpex } = setup(); | ||
type Foo = string; | ||
|
||
expect(() => jpex.resolve<Foo>()).toThrow(); | ||
}); | ||
|
||
test('if factory does not exist and default is undefined, it should return undefined', () => { | ||
const { jpex } = setup(); | ||
type Foo = string; | ||
|
||
const result = jpex.resolve<Foo>({ default: undefined }); | ||
|
||
expect(result).toBe(undefined); | ||
}); |
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