Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 65db09f

Browse files
author
MattAgn
committedJun 4, 2022
test: add tests for the matchers
1 parent 63c7dbe commit 65db09f

File tree

3 files changed

+80
-0
lines changed

3 files changed

+80
-0
lines changed
 
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { matchArrayValue } from '../matchArrayValue';
2+
3+
test('returns true given 2 identical prop and matcher', () => {
4+
expect(matchArrayValue(['banana'], ['banana'])).toEqual(true);
5+
expect(matchArrayValue(['banana', 'apple'], ['banana', 'apple'])).toEqual(
6+
true
7+
);
8+
});
9+
10+
test('returns true when the prop contains all the values of the matcher', () => {
11+
expect(
12+
matchArrayValue(['banana', 'apple', 'orange'], ['banana', 'orange'])
13+
).toEqual(true);
14+
});
15+
16+
test('returns false when the prop does not contain all the values of the matcher', () => {
17+
expect(
18+
matchArrayValue(['banana', 'apple', 'orange'], ['banana', 'pear'])
19+
).toEqual(false);
20+
});
21+
22+
test('returns false when prop is undefined', () => {
23+
expect(matchArrayValue(undefined, ['banana'])).toEqual(false);
24+
});
25+
26+
test('returns false when the matcher is an empty list', () => {
27+
expect(matchArrayValue(['banana'], [])).toEqual(false);
28+
});
29+
30+
test('returns false given 2 different prop and matchers', () => {
31+
expect(matchArrayValue(['banana', 'apple'], ['banana', 'orange'])).toEqual(
32+
false
33+
);
34+
});
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { matchObject } from '../matchObject';
2+
3+
test('returns true given 2 identical objects', () => {
4+
expect(matchObject({ fruit: 'banana' }, { fruit: 'banana' })).toEqual(true);
5+
expect(
6+
matchObject(
7+
{ fruit: 'banana', isRipe: true },
8+
{ fruit: 'banana', isRipe: true }
9+
)
10+
).toEqual(true);
11+
});
12+
13+
test('returns false when one of the param is an empty object', () => {
14+
expect(matchObject({}, { fruit: 'banana' })).toEqual(false);
15+
expect(matchObject({ fruit: 'banana' }, {})).toEqual(false);
16+
});
17+
18+
test('returns false given an undefined prop', () => {
19+
expect(matchObject(undefined, { fruit: 'banana' })).toEqual(false);
20+
});
21+
22+
test('returns false given 2 different non empty objects', () => {
23+
expect(matchObject({ fruit: 'banana' }, { fruits: 'banana' })).toEqual(false);
24+
expect(matchObject({ fruit: 'banana' }, { fruit: 'orange' })).toEqual(false);
25+
expect(
26+
matchObject(
27+
{ fruit: 'banana', isRipe: true },
28+
{ fruit: 'banana', ripe: true }
29+
)
30+
).toEqual(false);
31+
});
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { matchStringValue } from '../matchStringValue';
2+
3+
test.each`
4+
prop | matcher | expectedResult
5+
${'hey'} | ${'hey'} | ${true}
6+
${'hey'} | ${/hey/} | ${true}
7+
${'hey'} | ${'heyyyy'} | ${false}
8+
${'hey'} | ${/heyyy/} | ${false}
9+
${undefined} | ${'hey'} | ${false}
10+
`(
11+
'returns $expectedResult given prop $prop and matcher $matcher',
12+
({ prop, matcher, expectedResult }) => {
13+
expect(matchStringValue(prop, matcher)).toEqual(expectedResult);
14+
}
15+
);

0 commit comments

Comments
 (0)
Please sign in to comment.