Skip to content

Commit

Permalink
feat(hooks): add useState hook
Browse files Browse the repository at this point in the history
  • Loading branch information
u3u committed Jul 8, 2019
1 parent b3c540a commit 607dfd1
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/__tests__/useState.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import useState from '../useState';
import renderHook from '../util/renderHook';

describe('useState', () => {
it('should be defined', () => {
expect(useState).toBeDefined();
});

it('should update state', () => {
type Inject = { count1: number; count2: number };
const { vm } = renderHook<Inject>(() => ({
...useState({ count1: 'count' }),
...useState('test', { count2: 'count' }),
}));
expect(vm.count1).toBe(0);
expect(vm.count2).toBe(0);

vm.$store.commit('increment');
vm.$store.commit('test/decrement');

expect(vm.count1).toBe(1);
expect(vm.count2).toBe(-1);
});
});
3 changes: 3 additions & 0 deletions src/useState.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import createVuexHelper, { Helper } from './util/helpers';

export default createVuexHelper(Helper.State);

0 comments on commit 607dfd1

Please sign in to comment.