Skip to content

Commit

Permalink
Add requester.
Browse files Browse the repository at this point in the history
  • Loading branch information
ericmackrodt committed Jul 2, 2019
1 parent 52c2bff commit 7026d33
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
42 changes: 42 additions & 0 deletions packages/core/src/__tests__/requester.test.ts
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);
});
});
1 change: 1 addition & 0 deletions packages/core/src/__tests__/staat.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ describe('staat', () => {
expect(typeof sut.subscribe).toBe('function');
expect(typeof sut.unsubscribe).toBe('function');
expect(typeof sut.reduce).toBe('function');
expect(typeof sut.request).toBe('function');
});

it('reduces the value', () => {
Expand Down

0 comments on commit 7026d33

Please sign in to comment.