Skip to content

Instantly share code, notes, and snippets.

@reneviering
Last active June 9, 2016 18:26
Show Gist options
  • Save reneviering/e0d804ae94b0ba80eaab0f492e6bc388 to your computer and use it in GitHub Desktop.
Save reneviering/e0d804ae94b0ba80eaab0f492e6bc388 to your computer and use it in GitHub Desktop.
ES6 Katas
// 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');
});
});
});
@reneviering
Copy link
Author

Challenge 1/79 (template strings - basics)

I decided to write a few lines after i completed a es6 challenge. It starts with a very simple first challenge. Ideal to get comfortable with the es6 kata test setup.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment