Commit 9ae927f9 authored by addyosmani's avatar addyosmani

merging sproutcore fork and adding initial qunit stub

parent 4518a412
/* ==== Scroll down to find where to put your styles :) ==== */
/* HTML5 ✰ Boilerplate */
html, body, div, span, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
abbr, address, cite, code, del, dfn, em, img, ins, kbd, q, samp,
small, strong, sub, sup, var, b, i, dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, figcaption, figure,
footer, header, hgroup, menu, nav, section, summary,
time, mark, audio, video {
margin: 0;
padding: 0;
border: 0;
font-size: 100%;
font: inherit;
vertical-align: baseline;
}
article, aside, details, figcaption, figure,
footer, header, hgroup, menu, nav, section {
display: block;
}
blockquote, q { quotes: none; }
blockquote:before, blockquote:after,
q:before, q:after { content: ''; content: none; }
ins { background-color: #ff9; color: #000; text-decoration: none; }
mark { background-color: #ff9; color: #000; font-style: italic; font-weight: bold; }
del { text-decoration: line-through; }
abbr[title], dfn[title] { border-bottom: 1px dotted; cursor: help; }
table { border-collapse: collapse; border-spacing: 0; }
hr { display: block; height: 1px; border: 0; border-top: 1px solid #ccc; margin: 1em 0; padding: 0; }
input, select { vertical-align: middle; }
body { font:13px/1.231 sans-serif; *font-size:small; }
select, input, textarea, button { font:99% sans-serif; }
pre, code, kbd, samp { font-family: monospace, sans-serif; }
html { overflow-y: scroll; }
a:hover, a:active { outline: none; }
ul, ol { margin-left: 2em; }
ol { list-style-type: decimal; }
nav ul, nav li { margin: 0; list-style:none; list-style-image: none; }
small { font-size: 85%; }
strong, th { font-weight: bold; }
td { vertical-align: top; }
sub, sup { font-size: 75%; line-height: 0; position: relative; }
sup { top: -0.5em; }
sub { bottom: -0.25em; }
pre { white-space: pre; white-space: pre-wrap; word-wrap: break-word; padding: 15px; }
textarea { overflow: auto; }
.ie6 legend, .ie7 legend { margin-left: -7px; }
input[type="radio"] { vertical-align: text-bottom; }
input[type="checkbox"] { margin-right: 5px;
vertical-align: middle; }
.ie7 input[type="checkbox"] { vertical-align: baseline; }
.ie6 input { vertical-align: text-bottom; }
label, input[type="button"], input[type="submit"], input[type="image"], button { cursor: pointer; }
button, input, select, textarea { margin: 0; }
input:valid, textarea:valid { }
input:invalid, textarea:invalid { border-radius: 1px; -moz-box-shadow: 0px 0px 5px red; -webkit-box-shadow: 0px 0px 5px red; box-shadow: 0px 0px 5px red; }
.no-boxshadow input:invalid, .no-boxshadow textarea:invalid { background-color: #f0dddd; }
::-moz-selection{ background: #FF5E99; color:#fff; text-shadow: none; }
::selection { background:#FF5E99; color:#fff; text-shadow: none; }
a:link { -webkit-tap-highlight-color: #FF5E99; }
button { width: auto; overflow: visible; }
.ie7 img { -ms-interpolation-mode: bicubic; }
body, select, input, textarea { color: #444; }
h1, h2, h3, h4, h5, h6 { font-weight: bold; }
a, a:active, a:visited { color: #607890; }
a:hover { color: #036; }
/*
// ========================================== \\
|| ||
|| Your styles ! ||
|| ||
\\ ========================================== //
*/
.ir { display: block; text-indent: -999em; overflow: hidden; background-repeat: no-repeat; text-align: left; direction: ltr; }
.hidden { display: none; visibility: hidden; }
.visuallyhidden { border: 0; clip: rect(0 0 0 0); height: 1px; margin: -1px; overflow: hidden; padding: 0; position: absolute; width: 1px; }
.visuallyhidden.focusable:active,
.visuallyhidden.focusable:focus { clip: auto; height: auto; margin: 0; overflow: visible; position: static; width: auto; }
.invisible { visibility: hidden; }
.clearfix:before, .clearfix:after { content: "\0020"; display: block; height: 0; overflow: hidden; }
.clearfix:after { clear: both; }
.clearfix { zoom: 1; }
@media all and (orientation:portrait) {
}
@media all and (orientation:landscape) {
}
@media screen and (max-device-width: 480px) {
/* html { -webkit-text-size-adjust:none; -ms-text-size-adjust:none; } */
}
@media print {
* { background: transparent !important; color: black !important; text-shadow: none !important; filter:none !important;
-ms-filter: none !important; }
a, a:visited { color: #444 !important; text-decoration: underline; }
a[href]:after { content: " (" attr(href) ")"; }
abbr[title]:after { content: " (" attr(title) ")"; }
.ir a:after, a[href^="javascript:"]:after, a[href^="#"]:after { content: ""; }
pre, blockquote { border: 1px solid #999; page-break-inside: avoid; }
thead { display: table-header-group; }
tr, img { page-break-inside: avoid; }
@page { margin: 0.5cm; }
p, h2, h3 { orphans: 3; widows: 3; }
h2, h3{ page-break-after: avoid; }
}
\ No newline at end of file
This diff is collapsed.
@import "compass/css3";
@import "compass/reset";
/* CSS Reset */
@include global-reset;
body {
line-height: 1;
font-family: "Lucida Grande", sans-serif;
font-size: 13px;
}
ol, ul {
list-style: none;
}
blockquote, q {
quotes: none;
}
blockquote:before, blockquote:after,
q:before, q:after {
content: '';
content: none;
}
table {
border-collapse: collapse;
border-spacing: 0;
}
/* App CSS */
body, html {
color: #777;
background-color: #F2F4F5;
}
.sc-view {
position: relative;
overflow: visible;
}
$width: 600px;
$border: 1px solid #bbb;
body {
@include box-shadow(rgba(0,0,0,0.6) 0 0 1px);
@include border-radius(8px);
$padding: 10px;
$header-height: 20px;
position: absolute;
width: $width;
left: 50%;
margin-top: 38px;
border: $border;
margin-left: -300px;
background-color: #fff;
padding: ($header-height + $padding * 2) $padding $padding;
.mark-all-done label {
margin-left: 5px;
font-weight: bold;
}
#stats {
overflow: hidden;
width: 100%;
padding: 5px $padding;
margin: $padding ($padding * -1);
background-color: #eee;
border-top: 1px solid #aaa;
border-bottom: 1px solid #aaa;
line-height: 25px;
.remaining {
float: left;
}
.sc-button {
@include background-image(linear-gradient(#F9F9F9 1%, #DDD, #F2F2F2, #F7F7F7));
border: 1px solid #828282;
color: #000;
float: right;
padding: 5px;
&:hover {
@include background-image(linear-gradient(#FFF 1%, #E2E2E2, #F7F7F7, #FCFCFC));
}
&.is-active {
@include background-image(linear-gradient(#EFEFEF 1%, #D3D3D3, #E8E8E8, #EDEDED));
}
}
}
input[type='text'] {
@include border-radius(5px);
@include single-box-shadow(rgba(0,0,0,0.6), 0, 0, 10px, -2px);
color: #999;
background-color: rgb(240,240,240);
width: $width - ($padding) - 2px;
font-size: 30px;
font-family: Helvetica, sans-serif;
padding: 5px;
border: $border;
font-weight: 500;
&::-webkit-input-placeholder {
color: #aaa;
}
}
h1 {
@include border-top-radius(8px);
@include background-image(linear-gradient(color-stops(white, rgb(244,244,244) 49%, rgb(237,237,237) 51%, #dedede)));
@include single-text-shadow(white, 0, 1px, 1px);
font-size: 15px;
position: absolute;
width: $width;
height: $header-height;
color: rgb(83,86,94);
top: 0;
left: 0;
padding: ($padding / 2) $padding;
border-bottom: $border;
}
.sc-checkbox {
input[type="checkbox"] {
margin-right: 7px;
}
}
ul {
margin: 10px 0 2px 0;
li {
padding: 5px;
&.is-done {
color: #B7B7B7;
text-decoration: line-through;
}
}
li:nth-child(odd) {
background-color: #F7F7F7;
}
}
}
<!doctype html>
<!--[if lt IE 7 ]> <html lang="en" class="no-js ie6"> <![endif]--> <!--[if IE 7 ]> <html lang="en" class="no-js ie7"> <![endif]--> <!--[if IE 8 ]> <html lang="en" class="no-js ie8"> <![endif]--> <!--[if IE 9 ]> <html lang="en" class="no-js ie9"> <![endif]-->
<!--[if (gt IE 9)|!(IE)]><!--> <html lang="en" class="no-js"> <!--<![endif]-->
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title></title>
<meta name="description" content="">
<meta name="author" content="">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="shortcut icon" href="/favicon.ico">
<link rel="apple-touch-icon" href="/apple-touch-icon.png">
<link rel="stylesheet" href="css/style.css?v=2">
<link rel="stylesheet" href="css/todos.css">
<!--[if lt IE 9]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
</head>
<body>
<div id="todoapp">
<div class="title">
<h1>Todos</h1>
</div>
<div class="content">
<script type="text/html">
{{#view id="create-todo"}}
{{view Todos.CreateTodoView id="new-todo" placeholder="What needs to be done?"}}
{{/view}}
{{view SC.Checkbox class="mark-all-done"
title="Mark all as done"
valueBinding="Todos.todosController.allAreDone"}}
{{#view id="todos"}}
{{#collection id="todo-list" contentBinding="Todos.todosController" tagName="ul" itemClassBinding="content.isDone"}}
{{view SC.Checkbox titleBinding="parentView.content.title"
valueBinding="parentView.content.isDone"}}
{{/collection}}
{{/view}}
<!-- Insert this after the CreateTodoView and before the collection. -->
{{#view Todos.StatsView id="todo-stats"}}
{{#view SC.Button classBinding="isActive"
target="Todos.todosController"
action="clearCompletedTodos"}}
Clear Completed
{{/view}}
{{remainingString}} remaining
{{/view}}
</script>
</div>
</div>
<div id="credits">
Credits:
<br />
Tom Dale, SproutCore, Updates: Addy Osmani
</div>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>
<script>!window.jQuery && document.write(unescape('%3Cscript src="js/libs/jquery-1.6.1.min.js"%3E%3C/script%3E'))</script>
<script src="js/libs/sproutcore-2.0.a.2.min.js"></script>
<script src="js/app.js"></script>
</body>
</html>
Todos = SC.Application.create();
Todos.Todo = SC.Object.extend({
title: null,
isDone: false
});
Todos.todosController = SC.ArrayProxy.create({
content: [],
createTodo: function(title) {
var todo = Todos.Todo.create({ title: title });
this.pushObject(todo);
},
clearCompletedTodos: function() {
this.filterProperty('isDone', true).forEach(this.removeObject, this);
},
remaining: function() {
return this.filterProperty('isDone', false).get('length');
}.property('@each.isDone'),
allAreDone: function(key, value) {
if (value !== undefined) {
this.setEach('isDone', value);
return value;
} else {
return !!this.get('length') && this.everyProperty('isDone', true);
}
}.property('@each.isDone')
});
Todos.StatsView = SC.View.extend({
remainingBinding: 'Todos.todosController.remaining',
remainingString: function() {
var remaining = this.get('remaining');
return remaining + (remaining === 1 ? " item" : " items");
}.property('remaining')
});
Todos.CreateTodoView = SC.TextField.extend({
insertNewline: function() {
var value = this.get('value');
if (value) {
Todos.todosController.createTodo(value);
this.set('value', '');
}
}
});
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
/**
* QUnit - A JavaScript Unit Testing Framework
*
* http://docs.jquery.com/QUnit
*
* Copyright (c) 2011 John Resig, Jörn Zaefferer
* Dual licensed under the MIT (MIT-LICENSE.txt)
* or GPL (GPL-LICENSE.txt) licenses.
*/
/** Font Family and Sizes */
#qunit-tests, #qunit-header, #qunit-banner, #qunit-testrunner-toolbar, #qunit-userAgent, #qunit-testresult {
font-family: "Helvetica Neue Light", "HelveticaNeue-Light", "Helvetica Neue", Calibri, Helvetica, Arial, sans-serif;
}
#qunit-testrunner-toolbar, #qunit-userAgent, #qunit-testresult, #qunit-tests li { font-size: small; }
#qunit-tests { font-size: smaller; }
/** Resets */
#qunit-tests, #qunit-tests ol, #qunit-header, #qunit-banner, #qunit-userAgent, #qunit-testresult {
margin: 0;
padding: 0;
}
/** Header */
#qunit-header {
padding: 0.5em 0 0.5em 1em;
color: #8699a4;
background-color: #0d3349;
font-size: 1.5em;
line-height: 1em;
font-weight: normal;
border-radius: 15px 15px 0 0;
-moz-border-radius: 15px 15px 0 0;
-webkit-border-top-right-radius: 15px;
-webkit-border-top-left-radius: 15px;
}
#qunit-header a {
text-decoration: none;
color: #c2ccd1;
}
#qunit-header a:hover,
#qunit-header a:focus {
color: #fff;
}
#qunit-banner {
height: 5px;
}
#qunit-testrunner-toolbar {
padding: 0.5em 0 0.5em 2em;
color: #5E740B;
background-color: #eee;
}
#qunit-userAgent {
padding: 0.5em 0 0.5em 2.5em;
background-color: #2b81af;
color: #fff;
text-shadow: rgba(0, 0, 0, 0.5) 2px 2px 1px;
}
/** Tests: Pass/Fail */
#qunit-tests {
list-style-position: inside;
}
#qunit-tests li {
padding: 0.4em 0.5em 0.4em 2.5em;
border-bottom: 1px solid #fff;
list-style-position: inside;
}
#qunit-tests.hidepass li.pass, #qunit-tests.hidepass li.running {
display: none;
}
#qunit-tests li strong {
cursor: pointer;
}
#qunit-tests li a {
padding: 0.5em;
color: #c2ccd1;
text-decoration: none;
}
#qunit-tests li a:hover,
#qunit-tests li a:focus {
color: #000;
}
#qunit-tests ol {
margin-top: 0.5em;
padding: 0.5em;
background-color: #fff;
border-radius: 15px;
-moz-border-radius: 15px;
-webkit-border-radius: 15px;
box-shadow: inset 0px 2px 13px #999;
-moz-box-shadow: inset 0px 2px 13px #999;
-webkit-box-shadow: inset 0px 2px 13px #999;
}
#qunit-tests table {
border-collapse: collapse;
margin-top: .2em;
}
#qunit-tests th {
text-align: right;
vertical-align: top;
padding: 0 .5em 0 0;
}
#qunit-tests td {
vertical-align: top;
}
#qunit-tests pre {
margin: 0;
white-space: pre-wrap;
word-wrap: break-word;
}
#qunit-tests del {
background-color: #e0f2be;
color: #374e0c;
text-decoration: none;
}
#qunit-tests ins {
background-color: #ffcaca;
color: #500;
text-decoration: none;
}
/*** Test Counts */
#qunit-tests b.counts { color: black; }
#qunit-tests b.passed { color: #5E740B; }
#qunit-tests b.failed { color: #710909; }
#qunit-tests li li {
margin: 0.5em;
padding: 0.4em 0.5em 0.4em 0.5em;
background-color: #fff;
border-bottom: none;
list-style-position: inside;
}
/*** Passing Styles */
#qunit-tests li li.pass {
color: #5E740B;
background-color: #fff;
border-left: 26px solid #C6E746;
}
#qunit-tests .pass { color: #528CE0; background-color: #D2E0E6; }
#qunit-tests .pass .test-name { color: #366097; }
#qunit-tests .pass .test-actual,
#qunit-tests .pass .test-expected { color: #999999; }
#qunit-banner.qunit-pass { background-color: #C6E746; }
/*** Failing Styles */
#qunit-tests li li.fail {
color: #710909;
background-color: #fff;
border-left: 26px solid #EE5757;
}
#qunit-tests > li:last-child {
border-radius: 0 0 15px 15px;
-moz-border-radius: 0 0 15px 15px;
-webkit-border-bottom-right-radius: 15px;
-webkit-border-bottom-left-radius: 15px;
}
#qunit-tests .fail { color: #000000; background-color: #EE5757; }
#qunit-tests .fail .test-name,
#qunit-tests .fail .module-name { color: #000000; }
#qunit-tests .fail .test-actual { color: #EE5757; }
#qunit-tests .fail .test-expected { color: green; }
#qunit-banner.qunit-fail { background-color: #EE5757; }
/** Result */
#qunit-testresult {
padding: 0.5em 0.5em 0.5em 2.5em;
color: #2b81af;
background-color: #D2E0E6;
border-bottom: 1px solid white;
}
/** Fixture */
#qunit-fixture {
position: absolute;
top: -10000px;
left: -10000px;
}
This diff is collapsed.
<!DOCTYPE html>
<html>
<head>
<title>QUnit Test Suite</title>
<link rel="stylesheet" href="../qunit/qunit.css" type="text/css" media="screen">
<script type="text/javascript" src="../qunit/qunit.js"></script>
<script type="text/javascript" src="test.js"></script>
<script type="text/javascript" src="same.js"></script>
<script>
var logs = ["begin", "testStart", "testDone", "log", "moduleStart", "moduleDone", "done"];
for (var i = 0; i < logs.length; i++) {
(function() {
var log = logs[i];
QUnit[log] = function() {
console.log(log, arguments);
};
})();
}
</script>
</head>
<body>
<div id="qunit-fixture">test markup</div>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>QUnit Test Suite</title>
<link rel="stylesheet" href="../qunit/qunit.css" type="text/css" media="screen">
<script type="text/javascript" src="../qunit/qunit.js"></script>
<script type="text/javascript" src="test.js"></script>
<script type="text/javascript" src="same.js"></script>
</head>
<body>
<h1 id="qunit-header">QUnit Test Suite</h1>
<h2 id="qunit-banner"></h2>
<div id="qunit-testrunner-toolbar"></div>
<h2 id="qunit-userAgent"></h2>
<ol id="qunit-tests"></ol>
<div id="qunit-fixture">test markup</div>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title>QUnit Test Suite</title>
<link rel="stylesheet" href="../qunit/qunit.css" type="text/css" media="screen">
<script type="text/javascript" src="../qunit/qunit.js"></script>
<script type="text/javascript" src="logs.js"></script>
</head>
<body>
<h1 id="qunit-header">QUnit Test Suite</h1>
<h2 id="qunit-banner"></h2>
<div id="qunit-testrunner-toolbar"></div>
<h2 id="qunit-userAgent"></h2>
<ol id="qunit-tests"></ol>
<div id="qunit-fixture">test markup</div>
</body>
</html>
// TODO disable reordering for this suite!
var begin = 0,
moduleStart = 0,
moduleDone = 0,
testStart = 0,
testDone = 0,
log = 0,
moduleContext,
moduleDoneContext,
testContext,
testDoneContext,
logContext;
QUnit.begin = function() {
begin++;
};
QUnit.done = function() {
};
QUnit.moduleStart = function(context) {
moduleStart++;
moduleContext = context;
};
QUnit.moduleDone = function(context) {
moduleDone++;
moduleDoneContext = context;
};
QUnit.testStart = function(context) {
testStart++;
testContext = context;
};
QUnit.testDone = function(context) {
testDone++;
testDoneContext = context;
};
QUnit.log = function(context) {
log++;
logContext = context;
};
var logs = ["begin", "testStart", "testDone", "log", "moduleStart", "moduleDone", "done"];
for (var i = 0; i < logs.length; i++) {
(function() {
var log = logs[i],
logger = QUnit[log];
QUnit[log] = function() {
console.log(log, arguments);
logger.apply(this, arguments);
};
})();
}
module("logs1");
test("test1", 13, function() {
equal(begin, 1);
equal(moduleStart, 1);
equal(testStart, 1);
equal(testDone, 0);
equal(moduleDone, 0);
deepEqual(logContext, {
result: true,
message: undefined,
actual: 0,
expected: 0
});
equal("foo", "foo", "msg");
deepEqual(logContext, {
result: true,
message: "msg",
actual: "foo",
expected: "foo"
});
strictEqual(testDoneContext, undefined);
deepEqual(testContext, {
name: "test1"
});
strictEqual(moduleDoneContext, undefined);
deepEqual(moduleContext, {
name: "logs1"
});
equal(log, 12);
});
test("test2", 10, function() {
equal(begin, 1);
equal(moduleStart, 1);
equal(testStart, 2);
equal(testDone, 1);
equal(moduleDone, 0);
deepEqual(testDoneContext, {
name: "test1",
failed: 0,
passed: 13,
total: 13
});
deepEqual(testContext, {
name: "test2"
});
strictEqual(moduleDoneContext, undefined);
deepEqual(moduleContext, {
name: "logs1"
});
equal(log, 22);
});
module("logs2");
test("test1", 9, function() {
equal(begin, 1);
equal(moduleStart, 2);
equal(testStart, 3);
equal(testDone, 2);
equal(moduleDone, 1);
deepEqual(testContext, {
name: "test1"
});
deepEqual(moduleDoneContext, {
name: "logs1",
failed: 0,
passed: 23,
total: 23
});
deepEqual(moduleContext, {
name: "logs2"
});
equal(log, 31);
});
test("test2", 8, function() {
equal(begin, 1);
equal(moduleStart, 2);
equal(testStart, 4);
equal(testDone, 3);
equal(moduleDone, 1);
deepEqual(testContext, {
name: "test2"
});
deepEqual(moduleContext, {
name: "logs2"
});
equal(log, 39);
});
This diff is collapsed.
test("module without setup/teardown (default)", function() {
expect(1);
ok(true);
});
test("expect in test", 3, function() {
ok(true);
ok(true);
ok(true);
});
test("expect in test", 1, function() {
ok(true);
});
module("setup test", {
setup: function() {
ok(true);
}
});
test("module with setup", function() {
expect(2);
ok(true);
});
test("module with setup, expect in test call", 2, function() {
ok(true);
});
var state;
module("setup/teardown test", {
setup: function() {
state = true;
ok(true);
},
teardown: function() {
ok(true);
}
});
test("module with setup/teardown", function() {
expect(3);
ok(true);
});
module("setup/teardown test 2");
test("module without setup/teardown", function() {
expect(1);
ok(true);
});
if (typeof setTimeout !== 'undefined') {
state = 'fail';
module("teardown and stop", {
teardown: function() {
equal(state, "done", "Test teardown.");
}
});
test("teardown must be called after test ended", function() {
expect(1);
stop();
setTimeout(function() {
state = "done";
start();
}, 13);
});
module("async setup test", {
setup: function() {
stop();
setTimeout(function(){
ok(true);
start();
}, 500);
}
});
asyncTest("module with async setup", function() {
expect(2);
ok(true);
start();
});
module("async teardown test", {
teardown: function() {
stop();
setTimeout(function(){
ok(true);
start();
}, 500);
}
});
asyncTest("module with async teardown", function() {
expect(2);
ok(true);
start();
});
module("asyncTest");
asyncTest("asyncTest", function() {
expect(2);
ok(true);
setTimeout(function() {
state = "done";
ok(true);
start();
}, 13);
});
asyncTest("asyncTest", 2, function() {
ok(true);
setTimeout(function() {
state = "done";
ok(true);
start();
}, 13);
});
test("sync", 2, function() {
stop();
setTimeout(function() {
ok(true);
start();
}, 13);
stop();
setTimeout(function() {
ok(true);
start();
}, 125);
});
}
module("save scope", {
setup: function() {
this.foo = "bar";
},
teardown: function() {
deepEqual(this.foo, "bar");
}
});
test("scope check", function() {
expect(2);
deepEqual(this.foo, "bar");
});
module("simple testEnvironment setup", {
foo: "bar",
bugid: "#5311" // example of meta-data
});
test("scope check", function() {
deepEqual(this.foo, "bar");
});
test("modify testEnvironment",function() {
this.foo="hamster";
});
test("testEnvironment reset for next test",function() {
deepEqual(this.foo, "bar");
});
module("testEnvironment with object", {
options:{
recipe:"soup",
ingredients:["hamster","onions"]
}
});
test("scope check", function() {
deepEqual(this.options, {recipe:"soup",ingredients:["hamster","onions"]}) ;
});
test("modify testEnvironment",function() {
// since we do a shallow copy, the testEnvironment can be modified
this.options.ingredients.push("carrots");
});
test("testEnvironment reset for next test",function() {
deepEqual(this.options, {recipe:"soup",ingredients:["hamster","onions","carrots"]}, "Is this a bug or a feature? Could do a deep copy") ;
});
module("testEnvironment tests");
function makeurl() {
var testEnv = QUnit.current_testEnvironment;
var url = testEnv.url || 'http://example.com/search';
var q = testEnv.q || 'a search test';
return url + '?q='+encodeURIComponent(q);
}
test("makeurl working",function() {
equal( QUnit.current_testEnvironment, this, 'The current testEnvironment is global');
equal( makeurl(), 'http://example.com/search?q=a%20search%20test', 'makeurl returns a default url if nothing specified in the testEnvironment');
});
module("testEnvironment with makeurl settings", {
url: 'http://google.com/',
q: 'another_search_test'
});
test("makeurl working with settings from testEnvironment", function() {
equal( makeurl(), 'http://google.com/?q=another_search_test', 'rather than passing arguments, we use test metadata to form the url');
});
test("each test can extend the module testEnvironment", {
q:'hamstersoup'
}, function() {
equal( makeurl(), 'http://google.com/?q=hamstersoup', 'url from module, q from test');
});
module("jsDump");
test("jsDump output", function() {
equals( QUnit.jsDump.parse([1, 2]), "[\n 1,\n 2\n]" );
equals( QUnit.jsDump.parse({top: 5, left: 0}), "{\n \"top\": 5,\n \"left\": 0\n}" );
if (typeof document !== 'undefined' && document.getElementById("qunit-header")) {
equals( QUnit.jsDump.parse(document.getElementById("qunit-header")), "<h1 id=\"qunit-header\"></h1>" );
equals( QUnit.jsDump.parse(document.getElementsByTagName("h1")), "[\n <h1 id=\"qunit-header\"></h1>\n]" );
}
});
module("assertions");
test("raises",function() {
function CustomError( message ) {
this.message = message;
}
CustomError.prototype.toString = function() {
return this.message;
};
raises(
function() {
throw "error"
}
);
raises(
function() {
throw "error"
},
'raises with just a message, no expected'
);
raises(
function() {
throw new CustomError();
},
CustomError,
'raised error is an instance of CustomError'
);
raises(
function() {
throw new CustomError("some error description");
},
/description/,
"raised error message contains 'description'"
);
raises(
function() {
throw new CustomError("some error description");
},
function( err ) {
if ( (err instanceof CustomError) && /description/.test(err) ) {
return true;
}
},
"custom validation function"
);
});
if (typeof document !== "undefined") {
module("fixture");
test("setup", function() {
document.getElementById("qunit-fixture").innerHTML = "foobar";
});
test("basics", function() {
equal( document.getElementById("qunit-fixture").innerHTML, "test markup", "automatically reset" );
});
}
module("custom assertions");
(function() {
function mod2(value, expected, message) {
var actual = value % 2;
QUnit.push(actual == expected, actual, expected, message);
}
test("mod2", function() {
mod2(2, 0, "2 % 2 == 0");
mod2(3, 1, "3 % 2 == 1");
})
})();
(function() {
var reset = QUnit.reset;
function afterTest() {
ok( false, "reset should not modify test status" );
}
module("reset");
test("reset runs assertions", function() {
QUnit.reset = function() {
afterTest();
reset.apply( this, arguments );
};
});
test("reset runs assertions2", function() {
QUnit.reset = reset;
});
})();
module("noglobals", {
teardown: function() {
delete window.badGlobalVariableIntroducedInTest;
}
});
test("let teardown clean up globals", function() {
// this test will always pass if run without ?noglobals=true
window.badGlobalVariableIntroducedInTest = true;
});
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment