Skip to content

Commit

Permalink
chore: more tests for matching
Browse files Browse the repository at this point in the history
  • Loading branch information
vvscode committed Dec 4, 2023
1 parent 07b39d8 commit b4ccd5e
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion src/utils/deep-partially-match.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,34 @@ describe('deepPartiallyMatch with deepPartial', () => {
expect(deepPartiallyMatch(item1, item2)).toBe(true);
});

it('should return true for HistoryItems with partial match and nested objects', () => {
it('should return true for HistoryItems with partial match and partial match nested objects', () => {
const item1: HistoryItem = { type: 'call', key: 'b', args: [{ nested: 42, other: 'value' }] };
const item2: DeepPartial<HistoryItem> = { type: 'call', key: 'b', args: [{ nested: 42 }] };
expect(deepPartiallyMatch(item1, item2)).toBe(true);
});

it('should return true for HistoryItems with partial match and partial nesting (no objects in the list)', () => {
const item1: HistoryItem = { type: 'call', key: 'b', args: [{ nested: 42, other: 'value' }] };
const item2: DeepPartial<HistoryItem> = { type: 'call', key: 'b', args: [] };
expect(deepPartiallyMatch(item1, item2)).toBe(true);
});

it('should return false for HistoryItems with partial match and partial micmatch on nesting', () => {
const item1: HistoryItem = { type: 'call', key: 'b', args: [{ nested: 42, other: 'value' }] };
const item2: DeepPartial<HistoryItem> = {
type: 'call',
key: 'b',
args: [{ value: 42, other: 'other value' }],
};
expect(deepPartiallyMatch(item1, item2)).toBe(false);
});

it('should return true for HistoryItems with partial match and partial nesting (no list)', () => {
const item1: HistoryItem = { type: 'call', key: 'b', args: [{ nested: 42, other: 'value' }] };
const item2: DeepPartial<HistoryItem> = { type: 'call', key: 'b' };
expect(deepPartiallyMatch(item1, item2)).toBe(true);
});

it('should return false for non-matching HistoryItems with nested objects', () => {
const item1: HistoryItem = { type: 'get', key: 'a', args: [{ nested: 42 }] };
const item2: HistoryItem = { type: 'get', key: 'a', args: [{ nested: 43 }] };
Expand Down

0 comments on commit b4ccd5e

Please sign in to comment.