Last active
February 28, 2017 15:07
-
-
Save reneviering/57104e2238acc6b3172350df2c78ae16 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// 2: template strings - multiline | |
// To do: make all tests pass, leave the asserts unchanged! | |
describe('template string, can contain multiline content', function() { | |
it('a normal string can`t span across multiple lines', function() { | |
var normalString = 'line1' + | |
'\n' + | |
'line2'; | |
assert.equal(normalString, 'line1\nline2'); | |
}); | |
it('wrapped in backticks it can span over multiple lines', function() { | |
var templateString = `line1 | |
line2`; | |
assert.equal(templateString, 'line1\nline2'); | |
}); | |
it('even over more than two lines', function() { | |
var multiline = `line 1 | |
line 2 | |
line 3 | |
line 4`; | |
assert.equal(multiline.split('\n').length, 4); | |
}); | |
describe('and expressions inside work too', function() { | |
var x = 42; | |
it('like simple variables', function() { | |
var multiline = `line 1 | |
${x}`; | |
assert.equal(multiline, 'line 1\n 42'); | |
}); | |
it('also here spaces matter', function() { | |
var multiline = ` | |
${x}`; | |
assert.equal(multiline, '\n42'); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Challenge 2/79 (template strings - multiline)
Template strings are a cool thing in ES6 resp. ES2015. A potential use case is dynamic generation of markup-strings. Multiline is pretty cool, but in this kata the fact that spaces matter made me think a little. Especially because this doesn't look very beautiful inside the test code:
Anyway template strings will make the code easier to read!