-
-
Save scopevale/75e8aa3cd7240d78b136 to your computer and use it in GitHub Desktop.
JS Bin // source http://jsbin.com/beyufa
This file contains hidden or 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
<!DOCTYPE html> | |
<html> | |
<head> | |
<script src="https://fb.me/react-0.14.7.min.js"></script> | |
<script src="https://fb.me/react-dom-0.14.7.min.js"></script> | |
<script src="https://npmcdn.com/expect/umd/expect.min.js"></script> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/redux/3.3.1/redux.min.js"></script> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
<script id="jsbin-javascript"> | |
'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; | |
} | |
}; | |
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_ELSE' })).toEqual(1); | |
expect(counter(undefined, {})).toEqual(0); | |
console.log('Tests passed!'); | |
</script> | |
<script id="jsbin-source-javascript" type="text/javascript">const counter = (state = 0, action) => { | |
switch (action.type) { | |
case 'INCREMENT': | |
return state + 1; | |
case 'DECREMENT': | |
return state - 1; | |
default: | |
return state | |
} | |
} | |
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_ELSE'}) | |
).toEqual(1); | |
expect( | |
counter(undefined, {}) | |
).toEqual(0); | |
console.log('Tests passed!');</script></body> | |
</html> |
This file contains hidden or 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
'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; | |
} | |
}; | |
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_ELSE' })).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
Redux: Writing a Counter Reducer with tests
Getting Started with Redux - lesson 5