-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(differ): let respect values, not only keys
- Loading branch information
Showing
3 changed files
with
109 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import shallowSimilarity from './shallow-similarity'; | ||
|
||
describe('Utility function: shallowSimilarity', () => { | ||
it('should return 1 if both values are the same', () => { | ||
expect(shallowSimilarity('2', '2')).toBe(1); | ||
}); | ||
|
||
it('should return 0 if either value is null', () => { | ||
expect(shallowSimilarity(null, '2')).toBe(0); | ||
expect(shallowSimilarity('2', null)).toBe(0); | ||
}); | ||
|
||
it('should return 0 if either value is not an object', () => { | ||
expect(shallowSimilarity('2', 2)).toBe(0); | ||
}); | ||
|
||
it('should return 0 if both values are objects but have no common keys', () => { | ||
expect(shallowSimilarity({ a: 1 }, { b: 2 })).toBe(0); | ||
}); | ||
|
||
it('should return the correct value if both values are objects and have common keys', () => { | ||
expect(shallowSimilarity({ a: 1 }, { a: 1 })).toBe(1); | ||
expect(shallowSimilarity({ a: 1, b: 2 }, { a: 1, c: 3 })).toBe(0.5); | ||
expect(shallowSimilarity({ a: 1, b: 2 }, { a: 1, b: 2 })).toBe(1); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters