Skip to content

Commit

Permalink
suggestor spec - componentWillReceiveProps
Browse files Browse the repository at this point in the history
  • Loading branch information
carloluis committed Dec 23, 2017
1 parent ac60b88 commit e7d2c12
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions src/suggestor/__tests__/Suggestor.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,38 +213,37 @@ describe('Suggestor component', () => {
});

describe('componentWillReceiveProps', () => {
it('update state.value if props.value changed', () => {
const component = shallow(<Suggestor {...PROPS} />);
let component, setStateSpy;

beforeEach(() => {
component = shallow(<Suggestor {...PROPS} />);
setStateSpy = jest.spyOn(component.instance(), 'setState');
});

afterEach(() => {
expect(setStateSpy).toBeCalled();
});

it('update state.value if props.value changed', () => {
expect(component.state()).toMatchObject({ value: '' });

const value = 'xesturgy';

component.setProps({ value });

expect(component.state()).toMatchObject({ value });
});

it('update state.filtered if props.list changed', () => {
const component = shallow(<Suggestor {...PROPS} />);

expect(component.state().filtered.length).toBe(PROPS.list.length);

const list = ['one', 'two'];

component.setProps({ list });

expect(component.state().filtered.length).toBe(list.length);
});

it('should always call setState', () => {
const component = shallow(<Suggestor {...PROPS} />);

const spy = jest.spyOn(component.instance(), 'setState');

component.setProps({});

expect(spy).toBeCalled();
});
});

Expand Down

0 comments on commit e7d2c12

Please sign in to comment.