Skip to content

Instantly share code, notes, and snippets.

Created June 27, 2016 13:34
Show Gist options
  • Save anonymous/24f305ab805aed5166660bd266092ea1 to your computer and use it in GitHub Desktop.
Save anonymous/24f305ab805aed5166660bd266092ea1 to your computer and use it in GitHub Desktop.
JS Bin // source https://jsbin.com/cocipo
<!DOCTYPE html>
<html>
<head>
<script src="https://npmcdn.com/expect/umd/expect.min.js"></script>
<link href="http://extjs.cachefly.net/ext-3.1.0/resources/css/ext-all.css" rel="stylesheet" type="text/css" />
<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 (action.type === 'INCREMENT') {
return state + 1;
} else if (action.type === 'DECREMENT') {
return state - 1;
}
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);
console.log('Tests passed!');
</script>
<script id="jsbin-source-html" type="text/html"><!DOCTYPE html>
<html>
<head>
<script src="https://npmcdn.com/expect/umd/expect.min.js"><\/script>
<link href="//extjs.cachefly.net/ext-3.1.0/resources/css/ext-all.css" rel="stylesheet" type="text/css" />
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
</body>
</html></script>
<script id="jsbin-source-javascript" type="text/javascript">function counter(state, action){
if(action.type === 'INCREMENT'){
return state + 1;
}
else if(action.type === 'DECREMENT'){
return state - 1;
}
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);
console.log('Tests passed!');
</script></body>
</html>
'use strict';
function counter(state, action) {
if (action.type === 'INCREMENT') {
return state + 1;
} else if (action.type === 'DECREMENT') {
return state - 1;
}
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);
console.log('Tests passed!');
@getnamo
Copy link

getnamo commented Jun 27, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment