-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement wrap, fallback, more documentation
- Loading branch information
1 parent
443d055
commit ee47684
Showing
14 changed files
with
510 additions
and
62 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
File renamed without changes.
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,25 @@ | ||
import { expect } from 'chai'; | ||
import { stub } from 'sinon'; | ||
import { Policy } from './Policy'; | ||
|
||
describe('FallbackPolicy', () => { | ||
it('does not fall back when not necessary', async () => { | ||
const result = await Policy.handleAll() | ||
.fallback('error') | ||
.execute(() => 'ok'); | ||
expect(result).to.equal('ok'); | ||
}); | ||
|
||
it('returns a fallback and emits an error if necessary', async () => { | ||
const policy = await Policy.handleAll().fallback('error'); | ||
const onFallback = stub(); | ||
policy.onFallback(onFallback); | ||
|
||
const error = new Error('oh no!'); | ||
const result = await policy.execute(() => { | ||
throw error; | ||
}); | ||
expect(result).to.equal('error'); | ||
expect(onFallback).calledWith({ error }); | ||
}); | ||
}); |
Oops, something went wrong.