Skip to content

Instantly share code, notes, and snippets.

@lanbau
Forked from anonymous/index.html
Created January 11, 2017 11:51
Show Gist options
  • Save lanbau/8c2f56cc59af06b960ff9c35c0fa1138 to your computer and use it in GitHub Desktop.
Save lanbau/8c2f56cc59af06b960ff9c35c0fa1138 to your computer and use it in GitHub Desktop.
JS Bin // source https://jsbin.com/basacipojo
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
<script src="https://wzrd.in/standalone/expect@latest"></script>
</head>
<body>
<script id="jsbin-javascript">
/*
* Open the console tab
* to see that the tests pass.
*/
// Reducer Function
// State Default 0
// Take in State & Action & Return
'use strict';
var counter = function counter(state, action) {
if (state === undefined) state = 0;
switch (action.type) {
case 'INCREMENT':
return state + 1;
case 'DECREMENT':
return state - 1;
default:
return state;
}
};
// State = 1
expect(counter(0, { type: 'INCREMENT' })).toEqual(1);
// State = 2
expect(counter(1, { type: 'INCREMENT' })).toEqual(2);
// State = 1
expect(counter(2, { type: 'DECREMENT' })).toEqual(1);
// State = 0
expect(counter(1, { type: 'DECREMENT' })).toEqual(0);
// State = 1
expect(counter(1, { type: 'SOMETHING_ELSE' })).toEqual(1);
// State = 0
expect(counter(undefined, {})).toEqual(0);
console.log('Tests passed!');
</script>
<script id="jsbin-source-javascript" type="text/javascript">/*
* Open the console tab
* to see that the tests pass.
*/
// Reducer Function
// State Default 0
// Take in State & Action & Return
const counter = (state = 0, action) => {
switch (action.type) {
case 'INCREMENT':
return state + 1;
case 'DECREMENT':
return state - 1;
default:
return state;
}
}
// State = 1
expect(
counter(0, { type: 'INCREMENT' })
).toEqual(1);
// State = 2
expect(
counter(1, { type: 'INCREMENT' })
).toEqual(2);
// State = 1
expect(
counter(2, { type: 'DECREMENT' })
).toEqual(1);
// State = 0
expect(
counter(1, { type: 'DECREMENT' })
).toEqual(0);
// State = 1
expect(
counter(1, { type: 'SOMETHING_ELSE' })
).toEqual(1);
// State = 0
expect(
counter(undefined, {})
).toEqual(0);
console.log('Tests passed!');</script></body>
</html>
/*
* Open the console tab
* to see that the tests pass.
*/
// Reducer Function
// State Default 0
// Take in State & Action & Return
'use strict';
var counter = function counter(state, action) {
if (state === undefined) state = 0;
switch (action.type) {
case 'INCREMENT':
return state + 1;
case 'DECREMENT':
return state - 1;
default:
return state;
}
};
// State = 1
expect(counter(0, { type: 'INCREMENT' })).toEqual(1);
// State = 2
expect(counter(1, { type: 'INCREMENT' })).toEqual(2);
// State = 1
expect(counter(2, { type: 'DECREMENT' })).toEqual(1);
// State = 0
expect(counter(1, { type: 'DECREMENT' })).toEqual(0);
// State = 1
expect(counter(1, { type: 'SOMETHING_ELSE' })).toEqual(1);
// State = 0
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