Skip to content

Commit d95c386

Browse files
author
dphaener
committed
Finish store testing
This finishes the beginnings of the Alt Store testing functionality. It also updates the readme.
1 parent 97c1d19 commit d95c386

3 files changed

Lines changed: 25 additions & 38 deletions

File tree

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,18 @@ The `.test` function will be given the component instance and the helpers array.
7676
~~~
7777

7878
You can see more examples in the tests directory.
79+
80+
##Testing Alt Stores
81+
82+
You can now test Alt stores using the same API.
83+
84+
~~~js
85+
TestStore(MyStore, MyActions)
86+
.setInitialState({ todos: todos })
87+
.addTodo({ title: "Get Beer", complete: false })
88+
.test(({ state }) => {
89+
expect(state.todos).to.eql(expected);
90+
})
91+
~~~
92+
93+
You can see the full documentation on the Wiki

src/alt/store.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,12 @@
11
import 'harmony-reflect'
22
import alt from './alt'
3-
import AltTestingUtils from 'alt/utils/AltTestingUtils'
43

54
class TestStore {
65
constructor(store, actions) {
76
this.store = store
87
this.actions = actions
98
}
109

11-
setState(params = {}, callback = () => {}) {
12-
this.actions.setInitialState(params)
13-
callback.call(this, this.store)
14-
return this
15-
}
16-
1710
action(funcName, data) {
1811
this.actions[funcName].call(this, data)
1912
return this
@@ -39,5 +32,6 @@ export default function TestStoreWrapper(store, actions) {
3932
}
4033
}
4134
})
35+
4236
return proxy
4337
}

tests/store.jsx

Lines changed: 9 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -30,47 +30,25 @@ describe('TestStore', () => {
3030
}
3131
];
3232

33-
describe('#setState', () => {
34-
it('should wait for the state to be set before returning the promise', () => {
35-
TestStore(MyStore, MyActions)
36-
.setState({ todos: todos }, ({ state }) => {
37-
expect(state.todos).to.eql(todos);
38-
});
39-
});
40-
41-
it('should work without a callback', () => {
33+
describe('#action', () => {
34+
it('should call a method on the actions', () => {
4235
TestStore(MyStore, MyActions)
43-
.setState({ todos: todos })
36+
.setInitialState({ todos: todos })
37+
.action('addTodo', { title: "Get Beer", complete: false })
4438
.test(({ state }) => {
45-
expect(state.todos).to.eql(todos);
39+
expect(state.todos).to.eql(expected);
4640
});
4741
});
4842
});
4943

50-
describe('#action', () => {
51-
it('should call a method on the actions', () => {
44+
describe('proxy', () => {
45+
it('should proxy missing method calls to the call function', () => {
5246
TestStore(MyStore, MyActions)
53-
.setState({ todos: todos })
54-
.action('addTodo', { title: "Get Beer", complete: false })
47+
.setInitialState({ todos: todos })
48+
.addTodo({ title: "Get Beer", complete: false })
5549
.test(({ state }) => {
5650
expect(state.todos).to.eql(expected);
5751
});
5852
});
5953
});
60-
61-
//describe('proxy', () => {
62-
// it('should proxy missing method calls to the call function', () => {
63-
// TestStore(MyStore, MyActions)
64-
// .setState({ todos: todos })
65-
// .addTodo({ title: "Get Beer", complete: false })
66-
// .test(({ state }) => {
67-
// expect(state.todos).to.eql(expected);
68-
// });
69-
// });
70-
71-
// //it('should error out when a bad method is called', () => {
72-
// // TestStore(MyStore)
73-
// // .noWay()
74-
// //});
75-
//});
7654
});

0 commit comments

Comments
 (0)