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
it('should get render user details object', function () { | |
// Stub the get function | |
$myapp.get = function (url, callback) { | |
if (url === '/api/users?id=1') { | |
callback({ fname: 'Amit', lname: 'Gupta' }); | |
} else { | |
callback(false); | |
} | |
}; |
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
$myapp.get = function (url, callback) { | |
var requestListener = function () { | |
if (httpRequest.readyState === XMLHttpRequest.DONE) { | |
if (httpRequest.status === 200) { | |
var response = JSON.parse(httpRequest.response); | |
callback(response); | |
} else { | |
alert('There was a problem with the request'); | |
} | |
} |
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
it('should add a todo item to the list', function () { | |
var selector = document.querySelector('#selector'); | |
selector.innerHTML = '<form id="aform"><input type="text" name="todo-input"><button>Submit</button></form><ul id="todo-list"></ul>'; | |
var form = document.querySelector('#aform'); | |
form.elements['todo-input'].value = 'task 1'; | |
var ev = document.createEvent('HTMLEvents'); | |
ev.initEvent('submit', true, true); | |
form.dispatchEvent(ev); |
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
<body> | |
<form id="aform"> | |
<input type="text" name="todo-input"> | |
<button>Submit</button> | |
</form> | |
<ul id="todo-list"></ul> | |
<script src="app.js"></script> | |
</body> |
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
document.addEventListener('submit', function (event) { | |
event.preventDefault(); | |
var elements = document.querySelector('#aform').elements; | |
var todoItem = elements['todo-input'].value; | |
var todoList = document.querySelector('#todo-list'); | |
if (todoItem) { | |
todoList.innerHTML += '<li>' + todoItem + '</li>'; | |
} | |
}); |
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
(function () { | |
'use strict'; | |
// Create a global variable and expose it to the world | |
var $myapp = {}; | |
self.$myapp = $myapp; | |
$myapp.isValidDate = function (dateString) { | |
var dateRegex = /(0[1-9]|1[012])[- \/.](0[1-9]|[12][0-9]|3[01])[- \/.](19|20)\d\d/gi; | |
return dateRegex.test(dateString); |
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 lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<title>Test Runner</title> | |
</head> | |
<body> | |
<div id="selector"></div> | |
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
function assert(isTrue) { | |
if (!isTrue) { | |
throw new Error(); | |
} | |
} |
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
(function(){ | |
'use strict'; | |
/** | |
* test function | |
* @param {string} desc | |
* @param {function} fn | |
*/ | |
function it(desc, fn) { | |
try { |
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 lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<title>Search a List</title> | |
<style> | |
body { | |
font-family: Arial, Helvetica, sans-serif; | |
} |
NewerOlder