OpinonLab JS Interview - JS2
by chicagogrooves
HTML
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/mocha/2.1.0/mocha.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/mocha/2.1.0/mocha.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/chai/1.10.0/chai.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/sinon.js/1.7.3/sinon.js"></script>
<div class="ty hidden">
<p>Thank you for your feedback!</p>
<div class="int-support"></div>
</div>
<noscript>
<h1>Javascript Disabled</h1>
<p>Looks like you have javascript disabled or are using a browser that doesn't support it. You can still leave feedback. It just won't be as pretty or easy to do it.</p>
</noscript>
<form id="commentCard">
<div id="banner" role="banner">
<div class="pod">
<a href="" target="_blank" title="OpinionLab - Feedback Anytime. Anywhere">
<!--img src="{{bannerPath}}" alt="{{bannerAlt}}" -->
</a>
</div>
</div>
<div id="content" role="main">
<div class="pod">
<ol>
<li class="required"><span class="error-message hidden">Please choose an overall rating.</span>
<fieldset>
<legend aria-label="Overall Rating required">* Overall Rating</legend>
<input name="overall" id="overall_0" type="radio" value="1">
<label for="overall_0">- -</label>
<input name="overall" id="overall_1" type="radio" value="2">
<label for="overall_1">-</label>
<input name="overall" id="overall_2" type="radio" value="3">
<label for="overall_2">- +</label>
<input name="overall" id="overall_3" type="radio" value="4">
<label for="overall_3">+</label>
<input name="overall" id="overall_4" type="radio" value="5">
<label for="overall_4">+ +</label>
</fieldset>
</li>
<li><span class="error-message hidden">Please leave...
JavaScript
mocha.setup('bdd');
expect = chai.expect;
defineTests();
mocha.run();
function defineTests () {
describe('Character Counter', function(){
var charCounter = {
getCount: function(){ return 22; }
};
describe('#getCount', function(){
it('should have the count of characters', function(){
expect(charCounter.getCount()).to.equal("TODO");
});
});
});
}
function mockAjax() {
server = sinon.fakeServer.create();
Object.defineProperty(server, "autoRespondAfter",
{
get: function(){ return 5000*Math.random();}
});
server.respondWith(function(xhr){
console.info("Responding to", xhr.url);
xhr.respond(200, {"Content-Type": "application/json"}, "{}")
});
server.autoRespond = true;
}
mockAjax();
$("form").on("submit", function(e){
e.preventDefault();
$.post('/foopath', {});
$.post('/foopath2', {});
});