Skip to content

Commit

Permalink
fix more lint issues
Browse files Browse the repository at this point in the history
  • Loading branch information
developit committed Jan 17, 2017
1 parent a1b6fc2 commit fa09c66
Showing 1 changed file with 90 additions and 90 deletions.
180 changes: 90 additions & 90 deletions test/provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,101 +92,101 @@ describe('preact-redux', () => {
});
});

describe('connectAdvanced()', () => {
it('should connectAdvanced component to store', () => {
let initialState = {
a: 'a',
b: 'b'
};

let reducer = (state=initialState, action) => {
switch (action.type) {
case 'A': return { ...state, a: action.data };
case 'B': return { ...state, b: action.data };
default: return state;
}
};

let store = createStore(reducer);
let Child = sinon.stub().returns(<div />);

let spies = {};

function shallowDiffers (a, b) {
for (let i in a) if (!(i in b)) return true;
for (let i in b) if (a[i] !== b[i]) return true;
return false;
}

let ConnectedChild = connectAdvanced((dispatch) => {
/**
* from https://github.com/reactjs/react-redux/blob/master/docs/api.md
* If a consecutive call to selector returns the same object (===) as its previous call,
* the component will not be re-rendered.
* It's the responsibility of selector to return that previous object when appropriate.
*/
let result = {};
const onA = spies.onA = sinon.spy(data => dispatch({type: 'A', data}));
const onB = spies.onB = sinon.spy(data => dispatch({type: 'B', data}));

return ({a, b}, {c}) => {
const nextResult = {
a,
b,
c,
onA,
onB
};

if (shallowDiffers(result, nextResult)) {
result = nextResult;
}
return result;
};
})(Child);

render((
describe('connectAdvanced()', () => {
it('should connectAdvanced component to store', () => {
let initialState = {
a: 'a',
b: 'b'
};

let reducer = (state=initialState, action) => {
switch (action.type) {
case 'A': return { ...state, a: action.data };
case 'B': return { ...state, b: action.data };
default: return state;
}
};

let store = createStore(reducer);
let Child = sinon.stub().returns(<div />);

let spies = {};

function shallowDiffers (a, b) {
for (let i in a) if (!(i in b)) return true;
for (let i in b) if (a[i] !== b[i]) return true;
return false;
}

let ConnectedChild = connectAdvanced((dispatch) => {
/**
* from https://github.com/reactjs/react-redux/blob/master/docs/api.md
* If a consecutive call to selector returns the same object (===) as its previous call,
* the component will not be re-rendered.
* It's the responsibility of selector to return that previous object when appropriate.
*/
let result = {};
const onA = spies.onA = sinon.spy(data => dispatch({type: 'A', data}));
const onB = spies.onB = sinon.spy(data => dispatch({type: 'B', data}));

return ({a, b}, {c}) => {
const nextResult = {
a,
b,
c,
onA,
onB
};

if (shallowDiffers(result, nextResult)) {
result = nextResult;
}
return result;
};
})(Child);

render((
<Provider store={store}>
<ConnectedChild c="c" />
</Provider>
), document.createElement('div'));

expect(Child).to.have.been.calledOnce.and.calledWithMatch({
a: 'a',
b: 'b',
c: 'c',
onA: spies.onA,
onB: spies.onB
});

Child.reset();
spies.onA('aaa');
expect(Child).to.have.been.calledOnce.and.calledWithMatch({
a: 'aaa',
b: 'b',
c: 'c',
onA: spies.onA,
onB: spies.onB
});

Child.reset();
spies.onB('bbb');
expect(Child).to.have.been.calledOnce.and.calledWithMatch({
a: 'aaa',
b: 'bbb',
c: 'c',
onA: spies.onA,
onB: spies.onB
});
});
});
), document.createElement('div'));

expect(Child).to.have.been.calledOnce.and.calledWithMatch({
a: 'a',
b: 'b',
c: 'c',
onA: spies.onA,
onB: spies.onB
});

Child.reset();
spies.onA('aaa');
expect(Child).to.have.been.calledOnce.and.calledWithMatch({
a: 'aaa',
b: 'b',
c: 'c',
onA: spies.onA,
onB: spies.onB
});

Child.reset();
spies.onB('bbb');
expect(Child).to.have.been.calledOnce.and.calledWithMatch({
a: 'aaa',
b: 'bbb',
c: 'c',
onA: spies.onA,
onB: spies.onB
});
});
});

describe('jsnext:main', () => {
it('should export the correct interface', () => {
expect(Redux.Provider).to.be.a('function');
expect(Redux.connect).to.be.a('function');
expect(Redux.connectAdvanced).to.be.a('function');
});
it('should export the correct interface', () => {
expect(Redux.Provider).to.be.a('function');
expect(Redux.connect).to.be.a('function');
expect(Redux.connectAdvanced).to.be.a('function');
});
});
});

0 comments on commit fa09c66

Please sign in to comment.