@@ -5,42 +5,43 @@ import Connector from '../../src/components/connector';
55describe ( 'Connector' , ( ) => {
66 let store ;
77 let connect ;
8+ let scopeStub ;
89
910 beforeEach ( ( ) => {
1011 store = createStore ( ( state , action ) => ( {
11- foo : 'bar' ,
12- baz : action . payload ,
13- anotherState : 12 ,
14- childObject : { child : true }
12+ foo : 'bar' ,
13+ baz : action . payload ,
14+ anotherState : 12 ,
15+ childObject : { child : true }
1516 } ) ) ;
17+ scopeStub = { $on : ( ) => { } , $destroy : ( ) => { } } ;
1618 connect = Connector ( store ) ;
1719 } ) ;
1820
19- it ( 'Should throw when not passed a plain object as target' , ( ) => {
21+ it ( 'Should throw when not passed a $scope object as target' , ( ) => {
2022 expect ( connect . bind ( connect , ( ) => ( { } ) , ( ) => { } ) ) . toThrow ( ) ;
2123 expect ( connect . bind ( connect , ( ) => ( { } ) , 15 ) ) . toThrow ( ) ;
2224 expect ( connect . bind ( connect , ( ) => ( { } ) , undefined ) ) . toThrow ( ) ;
23- expect ( connect . bind ( connect , ( ) => ( { } ) , { } ) ) . toNotThrow ( ) ;
25+ expect ( connect . bind ( connect , ( ) => ( { } ) , { } ) ) . toThrow ( ) ;
26+
27+ expect ( connect . bind ( connect , ( ) => ( { } ) , scopeStub ) ) . toNotThrow ( ) ;
2428 } ) ;
2529
2630 it ( 'Should throw when selector does not return a plain object as target' , ( ) => {
27- expect ( connect . bind ( connect , state => state . foo , { } ) ) . toThrow ( ) ;
31+ expect ( connect . bind ( connect , state => state . foo , scopeStub ) ) . toThrow ( ) ;
2832 } ) ;
2933
30-
3134 it ( 'target should be extended with state once directly after creation' , ( ) => {
32- let target = { } ;
33- connect ( ( ) => ( { test : 1 } ) , target ) ;
34- expect ( target ) . toEqual ( { test : 1 } ) ;
35+ connect ( ( ) => ( { vm : { test : 1 } } ) , scopeStub ) ;
36+ expect ( scopeStub . vm ) . toEqual ( { test : 1 } ) ;
3537 } ) ;
3638
3739 it ( 'Should update the target passed to connect when the store updates' , ( ) => {
38- let target = { } ;
39- connect ( state => state , target ) ;
40+ connect ( state => state , scopeStub ) ;
4041 store . dispatch ( { type : 'ACTION' , payload : 0 } ) ;
41- expect ( target . baz ) . toBe ( 0 ) ;
42+ expect ( scopeStub . baz ) . toBe ( 0 ) ;
4243 store . dispatch ( { type : 'ACTION' , payload : 1 } ) ;
43- expect ( target . baz ) . toBe ( 1 ) ;
44+ expect ( scopeStub . baz ) . toBe ( 1 ) ;
4445 } ) ;
4546
4647 //does that still makes sense?
@@ -53,15 +54,4 @@ describe('Connector', () => {
5354 store.dispatch({type: 'ACTION', payload: 1});
5455 expect(counter).toBe(3);
5556 });*/
56-
57-
58- it ( 'Should return an unsubscribing function' , ( ) => {
59- let target = { } ;
60- let unsubscribe = connect ( state => state , target ) ;
61- store . dispatch ( { type : 'ACTION' , payload : 1 } ) ;
62- expect ( target . baz ) . toBe ( 1 ) ;
63- unsubscribe ( ) ;
64- store . dispatch ( { type : 'ACTION' , payload : 2 } ) ;
65- expect ( target . baz ) . toBe ( 1 ) ;
66- } ) ;
6757} ) ;
0 commit comments