Description
GraphQL.js has a ES6 string tag helper function under jsutils/dedent
that removes indentation from strings so that the unit tests can look nicer.
One undocumented side effect of the dedent
function however confused me when reading some of the tests: The tag also adds escape sequences to the dedented string. Take for example this test:
it('Prints String Field With String Arg With Default', () => {
const output = printSingleFieldSchema({
type: GraphQLString,
args: { argOne: { type: GraphQLString, defaultValue: 'tes\t de\fault' } },
});
expect(output).to.equal(dedent`
schema {
query: Root
}
type Root {
singleField(argOne: String = "tes\t de\fault"): String
}
`);
});
The output actually contains escape sequences, like "tes\\t de\\fault"
, but the test looks likes as if it expects the output to be a non-escaped string.
The reason for this is that the dedent
tag accesses string.raw
instead of string
.
I'm not sure whether this is intended or not. If it is, then it should at least be documented in jsutils/dedent
, because having such a side effect is not what you expect from a function called "dedent". It should also be documented that the function only looks at spaces, it does not dedent tab-based indentation.
If you me know whether you prefer fixing the documentation or fixing the behavior, I can create a PR.