Skip to content

Commit

Permalink
test(core): update onStateChange test to support prevState
Browse files Browse the repository at this point in the history
  • Loading branch information
francoischalifour committed Oct 22, 2020
1 parent 5e80cdd commit d39f4cf
Showing 1 changed file with 42 additions and 26 deletions.
68 changes: 42 additions & 26 deletions packages/autocomplete-core/src/__tests__/autocomplete.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,20 @@ describe('createAutocomplete', () => {
setHighlightedIndex(1);

expect(onStateChange).toHaveBeenCalledTimes(1);
expect(onStateChange).toHaveBeenCalledWith({
state: expect.objectContaining({ highlightedIndex: 1 }),
});
expect(onStateChange).toHaveBeenCalledWith(
expect.objectContaining({
state: expect.objectContaining({ highlightedIndex: 1 }),
})
);

setHighlightedIndex(null);

expect(onStateChange).toHaveBeenCalledTimes(2);
expect(onStateChange).toHaveBeenCalledWith({
state: expect.objectContaining({ highlightedIndex: null }),
});
expect(onStateChange).toHaveBeenCalledWith(
expect.objectContaining({
state: expect.objectContaining({ highlightedIndex: null }),
})
);
});

test('setQuery', () => {
Expand All @@ -46,9 +50,11 @@ describe('createAutocomplete', () => {
setQuery('query');

expect(onStateChange).toHaveBeenCalledTimes(1);
expect(onStateChange).toHaveBeenCalledWith({
state: expect.objectContaining({ query: 'query' }),
});
expect(onStateChange).toHaveBeenCalledWith(
expect.objectContaining({
state: expect.objectContaining({ query: 'query' }),
})
);
});

test('setSuggestions', () => {
Expand All @@ -62,9 +68,11 @@ describe('createAutocomplete', () => {
setSuggestions(suggestions);

expect(onStateChange).toHaveBeenCalledTimes(1);
expect(onStateChange).toHaveBeenCalledWith({
state: expect.objectContaining({ suggestions }),
});
expect(onStateChange).toHaveBeenCalledWith(
expect.objectContaining({
state: expect.objectContaining({ suggestions }),
})
);
});

test('setIsOpen', () => {
Expand All @@ -77,9 +85,11 @@ describe('createAutocomplete', () => {
setIsOpen(true);

expect(onStateChange).toHaveBeenCalledTimes(1);
expect(onStateChange).toHaveBeenCalledWith({
state: expect.objectContaining({ isOpen: true }),
});
expect(onStateChange).toHaveBeenCalledWith(
expect.objectContaining({
state: expect.objectContaining({ isOpen: true }),
})
);
});

test('setStatus', () => {
Expand All @@ -92,9 +102,11 @@ describe('createAutocomplete', () => {
setStatus('stalled');

expect(onStateChange).toHaveBeenCalledTimes(1);
expect(onStateChange).toHaveBeenCalledWith({
state: expect.objectContaining({ status: 'stalled' }),
});
expect(onStateChange).toHaveBeenCalledWith(
expect.objectContaining({
state: expect.objectContaining({ status: 'stalled' }),
})
);
});

test('setContext', () => {
Expand All @@ -107,17 +119,21 @@ describe('createAutocomplete', () => {
setContext({ nbArticles: 10 });

expect(onStateChange).toHaveBeenCalledTimes(1);
expect(onStateChange).toHaveBeenCalledWith({
state: expect.objectContaining({ context: { nbArticles: 10 } }),
});
expect(onStateChange).toHaveBeenCalledWith(
expect.objectContaining({
state: expect.objectContaining({ context: { nbArticles: 10 } }),
})
);

setContext({ nbProducts: 30 });

expect(onStateChange).toHaveBeenCalledTimes(2);
expect(onStateChange).toHaveBeenCalledWith({
state: expect.objectContaining({
context: { nbArticles: 10, nbProducts: 30 },
}),
});
expect(onStateChange).toHaveBeenCalledWith(
expect.objectContaining({
state: expect.objectContaining({
context: { nbArticles: 10, nbProducts: 30 },
}),
})
);
});
});

0 comments on commit d39f4cf

Please sign in to comment.