diff options
Diffstat (limited to 'spec/frontend/__helpers__/graphql_helpers.js')
-rw-r--r-- | spec/frontend/__helpers__/graphql_helpers.js | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/spec/frontend/__helpers__/graphql_helpers.js b/spec/frontend/__helpers__/graphql_helpers.js new file mode 100644 index 00000000000..63123aa046f --- /dev/null +++ b/spec/frontend/__helpers__/graphql_helpers.js @@ -0,0 +1,14 @@ +/** + * Returns a clone of the given object with all __typename keys omitted, + * including deeply nested ones. + * + * Only works with JSON-serializable objects. + * + * @param {object} An object with __typename keys (e.g., a GraphQL response) + * @returns {object} A new object with no __typename keys + */ +export const stripTypenames = (object) => { + return JSON.parse( + JSON.stringify(object, (key, value) => (key === '__typename' ? undefined : value)), + ); +}; |