-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix formatting and flow typing issues
- Loading branch information
Showing
3 changed files
with
10 additions
and
43 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 |
---|---|---|
@@ -1,51 +1,18 @@ | ||
import { expect } from 'chai'; | ||
|
||
import isObjectLike from '../jsutils/isObjectLike'; | ||
import mapValue from '../jsutils/mapValue'; | ||
import toJSONDeep from '../language/__tests__/toJSONDeep'; | ||
|
||
/** | ||
* Deeply transforms an arbitrary value to a JSON-safe value by calling toJSON | ||
* on any nested value which defines it. | ||
*/ | ||
function toJSONDeep(value) { | ||
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 default function expectJSON(actual) { | ||
export default function expectJSON(actual: mixed) { | ||
const actualJSON = toJSONDeep(actual); | ||
|
||
return { | ||
toDeepEqual(expected) { | ||
toDeepEqual(expected: mixed) { | ||
const expectedJSON = toJSONDeep(expected); | ||
expect(actualJSON).to.deep.equal(expectedJSON); | ||
}, | ||
toDeepNestedProperty(path, expected) { | ||
toDeepNestedProperty(path: string, expected: mixed) { | ||
const expectedJSON = toJSONDeep(expected); | ||
expect(actualJSON).to.deep.nested.property(path, expectedJSON); | ||
}, | ||
}; | ||
} | ||
|
||
export function expectToThrowJSON(fn) { | ||
function mapException() { | ||
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