Created
March 1, 2017 09:49
-
-
Save underwindfall/b3402488807fd238056ae9ee89976ddc to your computer and use it in GitHub Desktop.
Answers of Es6katas [http://es6katas.org/]
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
// 1: template strings - basics | |
// To do: make all tests pass, leave the asserts unchanged! | |
describe('a template string, is wrapped in ` (backticks) instead of \' or "', function() { | |
describe('by default, behaves like a normal string', function() { | |
it('just surrounded by backticks', function() { | |
var str = `like a string`; | |
assert.equal(str, 'like a string'); | |
}); | |
}); | |
var x = 42; | |
var y = 23; | |
describe('can evaluate variables, which are wrapped in "${" and "}"', function() { | |
it('e.g. a simple variable "${x}" just gets evaluated', function() { | |
var evaluated = `x=${x}`; | |
assert.equal(evaluated, 'x=' + x); | |
}); | |
it('multiple variables get evaluated too', function() { | |
var evaluated = `${x}+${y}`; | |
assert.equal(evaluated, x + '+' + y); | |
}); | |
}); | |
describe('can evaluate any expression, wrapped inside "${...}"', function() { | |
it('all inside "${...}" gets evaluated', function() { | |
var evaluated = `${x+y}`; | |
assert.equal(evaluated, x+y); | |
}); | |
it('inside "${...}" can also be a function call', function() { | |
function getDomain(){ | |
return document.domain; | |
} | |
var evaluated = `${getDomain()}`; | |
assert.equal(evaluated, 'tddbin.com'); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment