File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -116,6 +116,21 @@ Test(<TestComponent />)
116116
117117~~~
118118
119+ You can see more examples in the tests directory.
119120
121+ ##Testing Alt Stores
120122
121- You can see more examples in the tests directory.
123+ You can now test [ Alt] ( http://alt.js.org/ ) stores using the same API.
124+
125+ ~~~ js
126+ import TestStore from ' legit-tests/alt/store'
127+
128+ TestStore (MyStore, MyActions)
129+ .setInitialState ({ todos: todos })
130+ .addTodo ({ title: " Get Beer" , complete: false })
131+ .test (({ state }) => {
132+ expect (state .todos ).to .eql (expected);
133+ })
134+ ~~~
135+
136+ You can see the full documentation on the Wiki
Original file line number Diff line number Diff line change 11--full-trace
22--compilers js:babel/register
3+ --harmony-proxies
34--recursive ./tests/**/*.jsx
Original file line number Diff line number Diff line change 2828 },
2929 "homepage" : " https://github.com/legitcode/tests#readme" ,
3030 "devDependencies" : {
31+ "alt" : " ^0.17.3" ,
3132 "babel" : " ^5.8.23" ,
3233 "babel-core" : " ^5.8.25" ,
3334 "babel-eslint" : " ^4.1.3" ,
3738 "eslint" : " ^1.5.1" ,
3839 "eslint-plugin-react" : " ^3.4.2" ,
3940 "expect" : " ^1.10.0" ,
41+ "harmony-reflect" : " ^1.4.2" ,
4042 "mocha" : " ^2.3.3" ,
4143 "mocha-babel" : " ^3.0.0" ,
4244 "react-hot-loader" : " ^1.3.0" ,
Original file line number Diff line number Diff line change 1+ import Alt from 'alt'
2+
3+ export default new Alt ( )
Original file line number Diff line number Diff line change 1+ import 'harmony-reflect'
2+
3+ class TestStore {
4+ constructor ( store , actions ) {
5+ this . store = store
6+ this . actions = actions
7+ }
8+
9+ test ( callback ) {
10+ callback . call ( this , this . store )
11+ return this
12+ }
13+ }
14+
15+ export default function TestStoreWrapper ( store , actions ) {
16+ var proxy = new Proxy ( new TestStore ( store , actions ) , {
17+ get : function ( target , name ) {
18+ if ( name in target ) {
19+ return target [ name ]
20+ }
21+ else if ( name in target . actions ) {
22+ return ( params ) => {
23+ target . actions [ name ] ( params )
24+ return proxy
25+ }
26+ }
27+ }
28+ } )
29+
30+ return proxy
31+ }
Original file line number Diff line number Diff line change @@ -7,7 +7,6 @@ import { expect } from 'chai'
77import { TestComponent , TinyComponent } from './components'
88
99describe ( 'Find middleware' , ( ) => {
10-
1110 it ( 'should find div' , ( ) => {
1211 Test ( < TestComponent /> )
1312 . find ( 'div' )
Original file line number Diff line number Diff line change 1+ import { expect } from 'chai'
2+ import TestStore from '../src/alt/store'
3+
4+ import { MyStore , MyActions } from './testStore'
5+
6+ describe ( 'TestStore' , ( ) => {
7+ let todos = [
8+ {
9+ title : "Get Milk" ,
10+ complete : false
11+ } ,
12+ {
13+ title : "Get Bread" ,
14+ complete : false
15+ }
16+ ]
17+
18+ let expected = [
19+ {
20+ title : "Get Milk" ,
21+ complete : false
22+ } ,
23+ {
24+ title : "Get Bread" ,
25+ complete : false
26+ } ,
27+ {
28+ title : "Get Beer" ,
29+ complete : false
30+ }
31+ ]
32+
33+ describe ( 'proxy' , ( ) => {
34+ it ( 'should proxy missing method calls to the call function' , ( ) => {
35+ TestStore ( MyStore , MyActions )
36+ . setInitialState ( { todos : todos } )
37+ . addTodo ( { title : "Get Beer" , complete : false } )
38+ . test ( ( { state } ) => {
39+ expect ( state . todos ) . to . eql ( expected )
40+ } )
41+ } )
42+ } )
43+ } )
Original file line number Diff line number Diff line change 1+ import alt from '../src/alt/alt'
2+
3+ class myActions {
4+ constructor ( ) {
5+ this . generateActions ( 'addTodo' , 'setInitialState' )
6+ }
7+ }
8+
9+ const MyActions = alt . createActions ( myActions )
10+
11+ class myStore {
12+ constructor ( ) {
13+ this . bindActions ( MyActions )
14+ }
15+
16+ setInitialState ( params ) {
17+ this . setState ( params )
18+ }
19+
20+ addTodo ( todo ) {
21+ this . setState ( { todos : this . todos . concat ( todo ) } )
22+ }
23+ }
24+
25+ const MyStore = alt . createStore ( myStore , 'MyStore' )
26+ export { MyStore , MyActions }
You can’t perform that action at this time.
0 commit comments