Skip to content

Instantly share code, notes, and snippets.

@giopunt
Created July 6, 2017 15:40
Show Gist options
  • Save giopunt/a0d0161bfd0d34cd3a3548dfebca0558 to your computer and use it in GitHub Desktop.
Save giopunt/a0d0161bfd0d34cd3a3548dfebca0558 to your computer and use it in GitHub Desktop.
REDUX TRANING - EXPECTATIONS // source https://jsbin.com/sovojel
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>REDUX TRANING - EXPECTATIONS</title>
<script src="https://wzrd.in/standalone/expect@latest"></script>
<script src="https://wzrd.in/standalone/deep-freeze@latest"></script>
</head>
<body>
<h1>REDUX TRANING - EXPECTATIONS</h1>
<script id="jsbin-javascript">
'use strict';
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i]; return arr2; } else { return Array.from(arr); } }
var addCounter = function addCounter(list) {
return [].concat(_toConsumableArray(list), [0]);
};
var removeCounter = function removeCounter(list, index) {
return [].concat(_toConsumableArray(list.slice(0, index)), _toConsumableArray(list.slice(index + 1)));
};
var incrementCounter = function incrementCounter(list, index) {
return [].concat(_toConsumableArray(list.slice(0, index)), [list[index] + 1], _toConsumableArray(list.slice(index + 1)));
};
var testCounter = function testCounter() {
var listBefore = [];
var listAfter = [0];
deepFreeze(listBefore);
expect(addCounter(listBefore)).toEqual(listAfter);
expect(removeCounter(listAfter, 0)).toEqual(listBefore);
};
testCounter();
console.log('All test passed.');
</script>
<script id="jsbin-source-javascript" type="text/javascript">const addCounter = (list) => {
return [...list, 0];
}
const removeCounter = (list, index) => {
return [
...list.slice(0, index),
...list.slice(index + 1)
];
}
const incrementCounter = (list, index) => {
return [
...list.slice(0, index),
list[index] + 1,
...list.slice(index + 1)
];
}
const testCounter = () => {
const listBefore = [];
const listAfter = [0];
deepFreeze(listBefore);
expect(
addCounter(listBefore)
).toEqual(listAfter);
expect(
removeCounter(listAfter, 0)
).toEqual(listBefore);
}
testCounter();
console.log('All test passed.')</script></body>
</html>
'use strict';
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i]; return arr2; } else { return Array.from(arr); } }
var addCounter = function addCounter(list) {
return [].concat(_toConsumableArray(list), [0]);
};
var removeCounter = function removeCounter(list, index) {
return [].concat(_toConsumableArray(list.slice(0, index)), _toConsumableArray(list.slice(index + 1)));
};
var incrementCounter = function incrementCounter(list, index) {
return [].concat(_toConsumableArray(list.slice(0, index)), [list[index] + 1], _toConsumableArray(list.slice(index + 1)));
};
var testCounter = function testCounter() {
var listBefore = [];
var listAfter = [0];
deepFreeze(listBefore);
expect(addCounter(listBefore)).toEqual(listAfter);
expect(removeCounter(listAfter, 0)).toEqual(listBefore);
};
testCounter();
console.log('All test passed.');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment