Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: modify fns to adapt to new safe-stable-stringify package update (#…
- Loading branch information
1 parent
fa6ec13
commit c45c875
Showing
5 changed files
with
54 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`util/clone maintains same order: { | ||
name: 'object', | ||
type: 'object', | ||
isObject: true, | ||
} 1`] = ` | ||
{ | ||
"isObject": true, | ||
"name": "object", | ||
"type": "object", | ||
} | ||
`; |
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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
import { quickStringify } from './stringify'; | ||
|
||
export function clone<T>(input: T | null = null): T { | ||
return JSON.parse(quickStringify(input)); | ||
const stringifiedInput = quickStringify(input); | ||
return stringifiedInput ? JSON.parse(stringifiedInput) : null; | ||
} |
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,27 @@ | ||
import { fingerprint } from './fingerprint'; | ||
|
||
describe('util/fingerprint', () => { | ||
const obj: any = { | ||
name: 'object', | ||
type: 'object', | ||
isObject: true, | ||
}; | ||
|
||
const obj2: any = { | ||
type: 'object', | ||
name: 'object', | ||
isObject: true, | ||
}; | ||
|
||
it('returns empty string', () => { | ||
const res = fingerprint(undefined); | ||
expect(res).toBeEmptyString(); | ||
}); | ||
|
||
it('maintains deterministic order', () => { | ||
const res = fingerprint(obj); | ||
const res2 = fingerprint(obj2); | ||
expect(res).not.toEqual(JSON.stringify(obj)); // shows that safeStringify changes the original order | ||
expect(res).toEqual(res2); | ||
}); | ||
}); |
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