Skip to content

Instantly share code, notes, and snippets.

@raydot
Created November 26, 2019 19:22
Show Gist options
  • Save raydot/bb3d1ee850071fe30e861569cb1804a8 to your computer and use it in GitHub Desktop.
Save raydot/bb3d1ee850071fe30e861569cb1804a8 to your computer and use it in GitHub Desktop.
JS Bin // source https://jsbin.com/kecokez
<link href="http://nightly.enyojs.com/latest/enyo-nightly/enyo.css" rel="stylesheet" type="text/css" />
<script src="http://nightly.enyojs.com/latest/enyo-nightly/enyo.js"></script>
<script src="http://nightly.enyojs.com/latest/lib/layout/package.js"></script>
<script src="http://nightly.enyojs.com/latest/lib/onyx/package.js"></script>
<script src="http://nightly.enyojs.com/latest/lib/g11n/package.js"></script>
<script src="http://nightly.enyojs.com/latest/lib/canvas/package.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/expect/1.20.2/expect.min.js"></script>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<script id="jsbin-javascript">
'use strict';
function counter(state, action) {
// If a request is made against state and it doesn't exist, the
// function should return what it thinks is the initial state.
if (typeof state === 'undefined') {
return 0;
}
if (action.type === 'INCREMENT') {
return state + 1;
} else if (action.type === 'DECREMENT') {
return state - 1;
} else {
return state; // HANDLE UNKNOWN ACTIONS
}
}
expect(counter(0, { type: 'INCREMENT' })).toEqual(1);
expect(counter(1, { type: 'INCREMENT' })).toEqual(2);
expect(counter(2, { type: 'DECREMENT' })).toEqual(1);
expect(counter(1, { type: 'DECREMENT' })).toEqual(0);
expect(counter(1, { type: 'SOMETHING STRANGE' })).toEqual(1);
expect(counter(undefined, {})).toEqual(0);
console.log('Tests passed!');
</script>
<script id="jsbin-source-javascript" type="text/javascript">function counter(state, action) {
// If a request is made against state and it doesn't exist, the
// function should return what it thinks is the initial state.
if (typeof state === 'undefined') {
return 0;
}
if (action.type === 'INCREMENT') {
return state + 1;
} else if (action.type === 'DECREMENT') {
return state - 1;
} else {
return state; // HANDLE UNKNOWN ACTIONS
}
}
expect(
counter(0, { type: 'INCREMENT'})
).toEqual(1);
expect(
counter(1, { type: 'INCREMENT'})
).toEqual(2);
expect(
counter(2, { type: 'DECREMENT'})
).toEqual(1)
expect(
counter(1, {type: 'DECREMENT'})
).toEqual(0);
expect(
counter(1, { type: 'SOMETHING STRANGE'})
).toEqual(1)
expect(
counter(undefined, {})
).toEqual(0)
console.log('Tests passed!')</script></body>
</html>
'use strict';
function counter(state, action) {
// If a request is made against state and it doesn't exist, the
// function should return what it thinks is the initial state.
if (typeof state === 'undefined') {
return 0;
}
if (action.type === 'INCREMENT') {
return state + 1;
} else if (action.type === 'DECREMENT') {
return state - 1;
} else {
return state; // HANDLE UNKNOWN ACTIONS
}
}
expect(counter(0, { type: 'INCREMENT' })).toEqual(1);
expect(counter(1, { type: 'INCREMENT' })).toEqual(2);
expect(counter(2, { type: 'DECREMENT' })).toEqual(1);
expect(counter(1, { type: 'DECREMENT' })).toEqual(0);
expect(counter(1, { type: 'SOMETHING STRANGE' })).toEqual(1);
expect(counter(undefined, {})).toEqual(0);
console.log('Tests passed!');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment