Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Error.toStringTag change return string from 'Object' to 'GraphQLError' (
#3261) We maintained this hack for a long time to make our Errors compatible with with chai's `to.deep.equal`
- Loading branch information
1 parent
2df59f1
commit 9e584e3
Showing
21 changed files
with
347 additions
and
311 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,40 @@ | ||
import { expect } from 'chai'; | ||
|
||
import { mapValue } from '../jsutils/mapValue'; | ||
import { isObjectLike } from '../jsutils/isObjectLike'; | ||
|
||
/** | ||
* Deeply transforms an arbitrary value to a JSON-safe value by calling toJSON | ||
* on any nested value which defines it. | ||
*/ | ||
function toJSONDeep(value: unknown): unknown { | ||
if (!isObjectLike(value)) { | ||
return value; | ||
} | ||
|
||
if (typeof value.toJSON === 'function') { | ||
return value.toJSON(); | ||
} | ||
|
||
if (Array.isArray(value)) { | ||
return value.map(toJSONDeep); | ||
} | ||
|
||
return mapValue(value, toJSONDeep); | ||
} | ||
|
||
export function expectJSON(value: unknown) { | ||
return expect(toJSONDeep(value)); | ||
} | ||
|
||
export function expectToThrowJSON(fn: () => unknown) { | ||
function mapException(): unknown { | ||
try { | ||
return fn(); | ||
} catch (error) { | ||
throw toJSONDeep(error); | ||
} | ||
} | ||
|
||
return expect(mapException).to.throw(); | ||
} |
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
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
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
Oops, something went wrong.