-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Fix react tests * Add requester functions * Add requester.
- Loading branch information
1 parent
07e889e
commit f792d06
Showing
4 changed files
with
82 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import staat from '../staat'; | ||
import { Staat } from '../types'; | ||
|
||
type TestState = { | ||
count: number; | ||
}; | ||
|
||
const state: TestState = { | ||
count: 37, | ||
}; | ||
|
||
describe('requester', () => { | ||
let sut: Staat<TestState>; | ||
beforeEach(() => { | ||
sut = staat(state); | ||
}); | ||
|
||
it('selects from state', async () => { | ||
let value: number = 10; | ||
await sut.request(async ({ select }) => { | ||
value = select(s => s.count); | ||
}); | ||
|
||
expect(value).toBe(37); | ||
}); | ||
|
||
it('reduces state', async () => { | ||
await sut.request(async ({ reduce }) => { | ||
reduce(s => ({ ...s, count: 99 })); | ||
}); | ||
|
||
expect(sut.currentState.count).toBe(99); | ||
}); | ||
|
||
it('accepts arguments', async () => { | ||
await sut.request(async ({ reduce }, value: number) => { | ||
reduce(s => ({ ...s, count: value })); | ||
}, 489); | ||
|
||
expect(sut.currentState.count).toBe(489); | ||
}); | ||
}); |
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