-
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.
closes #78
- Loading branch information
Jack Ellis
committed
Aug 23, 2020
1 parent
b89ce83
commit 5348bba
Showing
6 changed files
with
120 additions
and
7 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
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,78 @@ | ||
import anyTest, { TestInterface } from 'ava'; | ||
import base, { JpexInstance } from '..'; | ||
|
||
const test: TestInterface<{ | ||
jpex: JpexInstance, | ||
}> = anyTest; | ||
|
||
test.beforeEach((t) => { | ||
const jpex = base.extend(); | ||
|
||
t.context = { | ||
jpex, | ||
}; | ||
}); | ||
|
||
test('it resolves with given values (js)', (t) => { | ||
const { jpex } = t.context; | ||
|
||
jpex.factory('A', [ 'B', 'C', 'D' ], (b, c, d) => { | ||
return b + c + d; | ||
}); | ||
|
||
const result = jpex.resolveWith('A', { | ||
B: 'b', | ||
C: 'c', | ||
D: 'd', | ||
}); | ||
|
||
t.is(result, 'bcd'); | ||
}); | ||
|
||
test('it resolves with given values (ts)', (t) => { | ||
const { jpex } = t.context; | ||
|
||
type A = string; | ||
type B = string; | ||
type C = string; | ||
type D = string; | ||
|
||
jpex.factory<A>((b: B, c: C, d: D) => b + c + d); | ||
|
||
const result = jpex.resolveWith<A>({ | ||
[jpex.infer<B>()]: 'b', | ||
[jpex.infer<C>()]: 'c', | ||
[jpex.infer<D>()]: 'd', | ||
}); | ||
|
||
t.is(result, 'bcd'); | ||
}); | ||
|
||
test('it resolves using type inference (1)', (t) => { | ||
const { jpex } = t.context; | ||
type A = string; | ||
type B = string; | ||
|
||
jpex.factory<A>((b: B) => `a${b}`); | ||
|
||
const result = jpex.resolveWith<A, B>([ 'b' ]); | ||
|
||
t.is(result, 'ab'); | ||
}); | ||
|
||
test('it resolves with type inference (6)', (t) => { | ||
const { jpex } = t.context; | ||
type A = string; | ||
type B = string; | ||
type C = string; | ||
type D = string; | ||
type E = string; | ||
type F = string; | ||
type G = string; | ||
|
||
jpex.factory<A>((b: B, c: C, d: D, e: E, f: F, g: G) => `a${b}${c}${d}${e}${f}${g}`); | ||
|
||
const result = jpex.resolveWith<A, B, C, D, E, F, G>([ 'b', 'c', 'd', 'e', 'f', 'g' ]); | ||
|
||
t.is(result, 'abcdefg'); | ||
}); |
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