-
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 #81
- Loading branch information
Jack Ellis
committed
Aug 27, 2020
1 parent
7aa641f
commit 0fe2f0e
Showing
7 changed files
with
124 additions
and
9 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,100 @@ | ||
import anyTest, { TestInterface } from 'ava'; | ||
import { jpex as base, JpexInstance } from '..'; | ||
|
||
const test: TestInterface<{ | ||
jpex: JpexInstance, | ||
jpex2: JpexInstance, | ||
}> = anyTest; | ||
|
||
test.beforeEach((t) => { | ||
const jpex = base.extend(); | ||
const jpex2 = jpex.extend(); | ||
|
||
t.context = { | ||
jpex, | ||
jpex2, | ||
}; | ||
}); | ||
|
||
test('active overwrites an existing factory', (t) => { | ||
const { jpex } = t.context; | ||
|
||
type A = string; | ||
jpex.factory<A>(() => 'a'); | ||
jpex.factory<A>(() => 'A', { precedence: 'active' }); | ||
|
||
const result = jpex.resolve<A>(); | ||
|
||
t.is(result, 'A'); | ||
}); | ||
|
||
test('active overwrites an inherited factory', (t) => { | ||
const { jpex, jpex2 } = t.context; | ||
|
||
type A = string; | ||
jpex.factory<A>(() => 'a'); | ||
jpex2.factory<A>(() => 'A', { precedence: 'active' }); | ||
|
||
const result = jpex2.resolve<A>(); | ||
|
||
t.is(result, 'A'); | ||
}); | ||
|
||
test('defaults to active', (t) => { | ||
const { jpex } = t.context; | ||
|
||
type A = string; | ||
jpex.factory<A>(() => 'a'); | ||
jpex.factory<A>(() => 'A'); | ||
|
||
const result = jpex.resolve<A>(); | ||
|
||
t.is(result, 'A'); | ||
}); | ||
|
||
test('passive is ignored over an existing factory', (t) => { | ||
const { jpex } = t.context; | ||
|
||
type A = string; | ||
jpex.factory<A>(() => 'a'); | ||
jpex.factory<A>(() => 'A', { precedence: 'passive' }); | ||
|
||
const result = jpex.resolve<A>(); | ||
|
||
t.is(result, 'a'); | ||
}); | ||
|
||
test('passive is ignored over an inherited factory', (t) => { | ||
const { jpex, jpex2 } = t.context; | ||
|
||
type A = string; | ||
jpex.factory<A>(() => 'a'); | ||
jpex2.factory<A>(() => 'A', { precedence: 'passive' }); | ||
|
||
const result = jpex2.resolve<A>(); | ||
|
||
t.is(result, 'a'); | ||
}); | ||
|
||
test('passive is used if it does not exist', (t) => { | ||
const { jpex2 } = t.context; | ||
|
||
type A = string; | ||
jpex2.factory<A>(() => 'A', { precedence: 'passive' }); | ||
|
||
const result = jpex2.resolve<A>(); | ||
|
||
t.is(result, 'A'); | ||
}); | ||
|
||
test('inherits passive from config', (t) => { | ||
const { jpex: base } = t.context; | ||
const jpex = base.extend({ precedence: 'passive' }); | ||
type A = string; | ||
jpex.factory<A>(() => 'a'); | ||
jpex.factory<A>(() => 'A'); | ||
|
||
const result = jpex.resolve<A>(); | ||
|
||
t.is(result, 'a'); | ||
}); |
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