Skip to content

Commit 2825dc1

Browse files
Updated Readme to indicate Wallabyjs support and resetting tests to red
1 parent f36eca0 commit 2825dc1

20 files changed

+138
-137
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ JavaScript Koans is an interactive learning environment that uses failing tests
55

66
The inspiration for this project comes from the Edgecase Ruby Koans and the book 'Javascript: The Good Parts'.
77

8-
Open the file jskoans.htm in your favourite browser and make the tests pass.
8+
Open the file jskoans.htm in your favourite browser and make the tests pass. This updated version also supports [Wallaby.js](https://wallabyjs.com/) which means you can run your tests right from your IDE; no browser required!
9+
10+
![JS Koans with Wallaby](js-koans-with-wallaby.gif)
911

1012
The koans use the [Qunit](http://qunitjs.com/) test syntax and test runner.
1113

js-koans-with-wallaby.gif

2.8 MB
Loading

support/tester.js

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -41,36 +41,36 @@ Array.prototype.equalTo = function(compareTo) {
4141

4242
QUnit.config.reorder = false;
4343

44-
// QUnit.done(function(results) {
45-
// var failures = results.failed;
46-
// var total = results.total;
47-
// if (failures > 0) {
48-
// var failed = $('ol#qunit-tests > li.fail');
49-
// failed.hide();
50-
// $(failed[0]).show();
51-
// }
52-
// if (failures < total) {
53-
// $('h3.welcome_message').hide();
54-
// }
55-
// if (failures > 0) {
56-
// $("#zen-help").show();
57-
// }
58-
// $("body").scrollTop($(document).height());
59-
// });
44+
QUnit.done(function(results) {
45+
// var failures = results.failed;
46+
// var total = results.total;
47+
// if (failures > 0) {
48+
// var failed = $('ol#qunit-tests > li.fail');
49+
// failed.hide();
50+
// $(failed[0]).show();
51+
// }
52+
// if (failures < total) {
53+
// $('h3.welcome_message').hide();
54+
// }
55+
// if (failures > 0) {
56+
// $("#zen-help").show();
57+
// }
58+
// $("body").scrollTop($(document).height());
59+
});
6060

6161
QUnit.log(function(result) {
62-
lastAssertLogReason = result.message;
62+
//lastAssertLogReason = result.message;
6363
});
6464

65-
// QUnit.testDone(function(result) {
66-
// var message;
67-
// if (!ignoreFurtherFailures && result.failed > 0) {
68-
// ignoreFurtherFailures = true;
69-
// message = "" + randomZenMessage() + "\nTry meditating on this: " + result.module + ": " + result.name + " (" + lastAssertLogReason + ")";
70-
// $("#zen-help").html(message.replace(/\n/g, "<br /><br />"));
71-
// console.log(message);
72-
// }
73-
// });
65+
QUnit.testDone(function(result) {
66+
// var message;
67+
// if (!ignoreFurtherFailures && result.failed > 0) {
68+
// ignoreFurtherFailures = true;
69+
// message = "" + randomZenMessage() + "\nTry meditating on this: " + result.module + ": " + result.name + " (" + lastAssertLogReason + ")";
70+
// $("#zen-help").html(message.replace(/\n/g, "<br /><br />"));
71+
// console.log(message);
72+
// }
73+
});
7474

7575
function randomZenMessage() {
7676
var randomIndex = Math.floor(Math.random() * zenMessages.length);

topics/about_arrays.js

100644100755
Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,23 @@ module("About Arrays (topics/about_arrays.js)");
22

33
test("array literal syntax and indexing", function() {
44
var favouriteThings = ["cellar door", 42, true]; // note that array elements do not have to be of the same type
5-
equal("cellar door", favouriteThings[0], 'what is in the first position of the array?');
6-
equal(42, favouriteThings[1], 'what is in the second position of the array?');
7-
equal(true, favouriteThings[2], 'what is in the third position of the array?');
5+
equal(__, favouriteThings[0], 'what is in the first position of the array?');
6+
equal(__, favouriteThings[1], 'what is in the second position of the array?');
7+
equal(__, favouriteThings[2], 'what is in the third position of the array?');
88
});
99

1010
test("array type", function() {
11-
equal("object", typeof([]), 'what is the type of an array?');
11+
equal(__, typeof([]), 'what is the type of an array?');
1212
});
1313

1414
test("length", function() {
1515
var collection = ['a','b','c'];
16-
equal(3, collection.length, 'what is the length of the collection array?');
16+
equal(__, collection.length, 'what is the length of the collection array?');
1717
});
1818

1919
test("splice", function() {
2020
var daysOfWeek = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'];
21-
var workingWeek = daysOfWeek.splice(0, 5);
21+
var workingWeek = daysOfWeek.splice(__, __);
2222
var weekend = daysOfWeek;
2323

2424
deepEqual(workingWeek, ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday'], 'what is the value of workingWeek?');
@@ -30,8 +30,8 @@ test("stack methods", function() {
3030
stack.push("first");
3131
stack.push("second");
3232

33-
equal("second", stack.pop(), 'what will be the first value popped off the stack?');
34-
equal("first", stack.pop(), 'what will be the second value popped off the stack?');
33+
equal(__, stack.pop(), 'what will be the first value popped off the stack?');
34+
equal(__, stack.pop(), 'what will be the second value popped off the stack?');
3535
});
3636

3737
test("queue methods", function() {
@@ -40,6 +40,6 @@ test("queue methods", function() {
4040
queue.push("second");
4141
queue.unshift("third");
4242

43-
equal("third", queue.shift(), 'what will be shifted out first?');
44-
equal("first", queue.shift(), 'what will be shifted out second?');
43+
equal(__, queue.shift(), 'what will be shifted out first?');
44+
equal(__, queue.shift(), 'what will be shifted out second?');
4545
});

topics/about_asserts.js

100644100755
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
module("About Asserts (topics/about_asserts.js)");
33

44
test("ok", function() {
5-
ok(true === true, 'what will satisfy the ok assertion?');
5+
ok(__ === true, 'what will satisfy the ok assertion?');
66
});
77

88
test("not ok", function() {
9-
ok(false === false, 'what is a false value?');
9+
ok(__ === false, 'what is a false value?');
1010
});
1111

1212
test("equal", function() {
13-
equal(2, 1 + 1, 'what will satisfy the equal assertion?');
13+
equal(__, 1 + 1, 'what will satisfy the equal assertion?');
1414
});

topics/about_assignment.js

100644100755
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
module("About Assignment (topics/about_assignment.js)");
33

44
test("local variables", function() {
5-
var temp = 1;
5+
var temp = __;
66
equal(temp, 1, "Assign a value to the variable temp");
77
});
88

99
test("global variables", function() {
1010
temp = 1; // Not using var is an example. Always use var in practise.
11-
equal(window.temp, temp, 'global variables are assigned to the window object');
11+
equal(window.__, temp, 'global variables are assigned to the window object');
1212
});

topics/about_control_structures.js

100644100755
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ test("if", function() {
55
if (2 > 0) {
66
isPositive = true;
77
}
8-
equal(true, isPositive, 'what is the value of isPositive?');
8+
equal(__, isPositive, 'what is the value of isPositive?');
99
});
1010

1111
test("for", function() {
1212
var counter = 10;
1313
for (var i = 1; i <= 3; i++) {
1414
counter = counter + i;
1515
}
16-
equal(16, counter, 'what is the value of counter?');
16+
equal(__, counter, 'what is the value of counter?');
1717
});
1818

1919
test("for in", function() {
@@ -27,15 +27,15 @@ test("for in", function() {
2727
for (var property_name in person) {
2828
result = result + property_name;
2929
}
30-
equal("nameage", result, 'what is the value of result?');
30+
equal(__, result, 'what is the value of result?');
3131
});
3232

3333
test("ternary operator", function() {
3434
var fruit = true ? "apple" : "orange";
35-
equal("apple", fruit, 'what is the value of fruit?');
35+
equal(__, fruit, 'what is the value of fruit?');
3636

3737
fruit = false ? "apple" : "orange";
38-
equal("orange", fruit, 'now what is the value of fruit?');
38+
equal(__, fruit, 'now what is the value of fruit?');
3939
});
4040

4141
test("switch", function() {
@@ -48,7 +48,7 @@ test("switch", function() {
4848
result = 2;
4949
break;
5050
}
51-
equal(2, result, 'what is the value of result?');
51+
equal(__, result, 'what is the value of result?');
5252
});
5353

5454
test("switch default case", function() {
@@ -64,10 +64,10 @@ test("switch default case", function() {
6464
result = "Merry";
6565
break;
6666
}
67-
equal("Merry", result, 'what is the value of result?');
67+
equal(__, result, 'what is the value of result?');
6868
});
6969

7070
test("null coalescing", function() {
7171
var result = null || "a value";
72-
equal("a value", result, 'what is the value of result?');
72+
equal(__, result, 'what is the value of result?');
7373
});

topics/about_equality.js

100644100755
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,22 @@
22
module("About Equality (topics/about_equality.js)");
33

44
test("numeric equality", function() {
5-
equal(3 + 4, 7, "");
5+
equal(3 + __, 7, "");
66
});
77

88
test("string equality", function() {
9-
equal("3" + "7", "37", "concatenate the strings");
9+
equal("3" + __, "37", "concatenate the strings");
1010
});
1111

1212
test("equality without type coercion", function() {
13-
ok(3 === 3, 'what is exactly equal to 3?');
13+
ok(3 === __, 'what is exactly equal to 3?');
1414
});
1515

1616
test("equality with type coercion", function() {
17-
ok(3 == "3", 'what string is equal to 3, with type coercion?');
17+
ok(3 == "__", 'what string is equal to 3, with type coercion?');
1818
});
1919

2020
test("string literals", function() {
21-
equal('frankenstein', "frankenstein", "quote types are interchangable, but must match.");
22-
equal("frankenstein", 'frankenstein', "quote types can use both single and double quotes.");
21+
equal(__, "frankenstein", "quote types are interchangable, but must match.");
22+
equal(__, 'frankenstein', "quote types can use both single and double quotes.");
2323
});

topics/about_functions_and_closure.js

100644100755
Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ test("defining functions directly", function() {
77
result = "b";
88
};
99
changeResult();
10-
equal('b', result, 'what is the value of result?');
10+
equal(__, result, 'what is the value of result?');
1111
});
1212

1313
test("assigning functions to variables", function() {
1414
var triple = function(input) {
1515
return input * 3;
1616
};
17-
equal(12, triple(4), 'what is triple 4?');
17+
equal(__, triple(4), 'what is triple 4?');
1818
});
1919

2020
test("self invoking functions", function() {
@@ -23,23 +23,23 @@ test("self invoking functions", function() {
2323
// self invoking functions are used to provide scoping and to alias variables
2424
(function(pv) {
2525
var secretValue = "password";
26-
equal("shared", pv, 'what is the value of pv?');
27-
equal("string", typeof(secretValue), "is secretValue available in this context?");
28-
equal("string", typeof(publicValue), "is publicValue available in this context?");
26+
equal(__, pv, 'what is the value of pv?');
27+
equal("__", typeof(secretValue), "is secretValue available in this context?");
28+
equal("__", typeof(publicValue), "is publicValue available in this context?");
2929
})(publicValue);
3030

31-
equal("undefined", typeof(secretValue), "is secretValue available in this context?");
32-
equal("string", typeof(publicValue), "is publicValue available in this context?");
31+
equal("__", typeof(secretValue), "is secretValue available in this context?");
32+
equal("__", typeof(publicValue), "is publicValue available in this context?");
3333
});
3434

3535
test("arguments array", function() {
3636
var add = function() {
3737
var total = 0;
3838
for(var i = 0; i < arguments.length; i++) {
3939
// complete the implementation of this method so that it returns the sum of its arguments
40-
total = total + arguments[i];
40+
// __
4141
}
42-
return total;
42+
// __
4343
};
4444

4545
equal(15, add(1,2,3,4,5), "add 1,2,3,4,5");
@@ -57,7 +57,7 @@ test("using call to invoke function",function(){
5757
//function, and the arguments to be sent to the function,multiple arguments are separated by commas.
5858
var result = invokee.call("I am this!", "Where did it come from?");
5959

60-
equal("I am this!Where did it come from?", result, "what will the value of invokee's this be?");
60+
equal(__, result, "what will the value of invokee's this be?");
6161
});
6262

6363
test("using apply to invoke function",function(){
@@ -70,6 +70,6 @@ test("using apply to invoke function",function(){
7070
//function and the second is the array of arguments to be passed into the called function.
7171
var result = invokee.apply("I am this!", ["I am arg1","I am arg2"]);
7272

73-
equal("I am this!I am arg1I am arg2", result, "what will the value of invokee's this be?");
73+
equal(__, result, "what will the value of invokee's this be?");
7474
});
7575

topics/about_numbers.js

100644100755
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ module("About Numbers (topics/about_numbers.js)");
44
test("types", function() {
55
var typeOfIntegers = typeof(6);
66
var typeOfFloats = typeof(3.14159);
7-
equal(true, typeOfIntegers === typeOfFloats, 'are ints and floats the same type?');
8-
equal("number", typeOfIntegers, 'what is the javascript numeric type?');
9-
equal(1, 1.0, 'what is a integer number equivalent to 1.0?');
7+
equal(__, typeOfIntegers === typeOfFloats, 'are ints and floats the same type?');
8+
equal(__, typeOfIntegers, 'what is the javascript numeric type?');
9+
equal(__, 1.0, 'what is a integer number equivalent to 1.0?');
1010
});
1111

1212
test("NaN", function() {
1313
var resultOfFailedOperations = 7/'apple';
14-
equal(true, isNaN(resultOfFailedOperations), 'what will satisfy the equals assertion?');
15-
equal(false, resultOfFailedOperations == NaN, 'is NaN == NaN?');
14+
equal(__, isNaN(resultOfFailedOperations), 'what will satisfy the equals assertion?');
15+
equal(__, resultOfFailedOperations == NaN, 'is NaN == NaN?');
1616
});

0 commit comments

Comments
 (0)