Open lydell opened 6 years ago
Hi! I just stumbled on a variation of this surprising-to-me behaviour.
As a worksaround, it's possible to do what I do in the second ('works'
): Replace \${hi}
with ${'${hi}'}
. That way, dedent
only sees a string literal and doesn't have to care about escaping.
I figured I'd share in case anyone else comes here looking for answers :smile:
// test.js
const dedent = require('dedent');
test('fails', () => {
const text = dedent`\${hi}`;
expect(text).toBe('${hi}');
});
test('works', () => {
const text = dedent`${'${hi}'}`;
expect(text).toBe('${hi}');
});
(y
is an alias for yarn
.)
(For people stumbling upon this issue: https://github.com/MartinKolarik/dedent-js might work better for you.)