Last active
February 27, 2017 16:01
-
-
Save DDDDDanica/3ca5f9db4aafe5baec2294d69aecb12a to your computer and use it in GitHub Desktop.
React, redux, Expect and Deep Freeze // source http://jsbin.com/bihacir
This file contains 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> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<script src="https://fb.me/react-0.14.3.min.js"></script> | |
<script src="https://fb.me/react-dom-0.14.3.min.js"></script> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/redux/3.0.4/redux.min.js"></script> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-redux/4.0.0/react-redux.js"></script> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/expect/1.20.2/expect.min.js"></script> | |
<script src="https://wzrd.in/standalone/deep-freeze@latest"></script> | |
<title>React, redux, Expect and Deep Freeze</title> | |
</head> | |
<body> | |
<script id="jsbin-javascript"> | |
'use strict'; | |
function testFunction(state, action) { | |
if (action.type === 'INCREMENT') { | |
return state + 1; | |
} else if (action.type === 'DECREMENT') { | |
return state - 1; | |
} else { | |
return state; | |
} | |
} | |
expect(testFunction(0, { type: 'INCREMENT' })).toEqual(1); | |
expect(testFunction(1, { type: 'INCREMENT' })).toEqual(2); | |
expect(testFunction(2, { type: 'DECREMENT' })).toEqual(1); | |
expect(testFunction(1, { type: 'DECREMENT' })).toEqual(0); | |
expect(testFunction(1, { type: 'SOMETHINGELSE' })).toEqual(1); | |
console.log('tests passed!'); | |
</script> | |
<script id="jsbin-source-javascript" type="text/javascript">function testFunction(state, action){ | |
if (action.type === 'INCREMENT') { | |
return state + 1; | |
} else if (action.type === 'DECREMENT') { | |
return state - 1; | |
} else { | |
return state; | |
} | |
} | |
expect( | |
testFunction(0, { type: 'INCREMENT'}) | |
).toEqual(1); | |
expect( | |
testFunction(1, { type: 'INCREMENT'}) | |
).toEqual(2); | |
expect( | |
testFunction(2, { type: 'DECREMENT'}) | |
).toEqual(1); | |
expect( | |
testFunction(1, { type: 'DECREMENT'}) | |
).toEqual(0); | |
expect( | |
testFunction(1, { type: 'SOMETHINGELSE'}) | |
).toEqual(1); | |
console.log('tests passed!'); | |
</script></body> | |
</html> |
This file contains 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'; | |
function testFunction(state, action) { | |
if (action.type === 'INCREMENT') { | |
return state + 1; | |
} else if (action.type === 'DECREMENT') { | |
return state - 1; | |
} else { | |
return state; | |
} | |
} | |
expect(testFunction(0, { type: 'INCREMENT' })).toEqual(1); | |
expect(testFunction(1, { type: 'INCREMENT' })).toEqual(2); | |
expect(testFunction(2, { type: 'DECREMENT' })).toEqual(1); | |
expect(testFunction(1, { type: 'DECREMENT' })).toEqual(0); | |
expect(testFunction(1, { type: 'SOMETHINGELSE' })).toEqual(1); | |
console.log('tests passed!'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment