Closed chrisgillis closed 11 years ago
It would seem you have to use \n characters and match the amount of spaces that toString() outputs exactly or the test will not pass. This seems poor.
Ah, didn't see this before opening my own issue on this.. yea, the script expects to receive:
'function (a, b) {\n return a * b;\n}'
It should accept:
'function (a, b) { return a * b; }'
In addition to these formating problems, it seems the latest version of chromium expects //An internal comment as well where as firefox does not.
I'm also having trouble with this one. This is the output I get:
Expected 'function (a, b) {
//An internal comment
return a * b;
}' to be 'function (a, b) {
//An internal comment
return a * b;
}'.
This is the debug message:
Error: Expected 'function (a, b) {
at null.<anonymous> (http://localhost/javascript-koans/koans/AboutFunctions.js:112:33)
This is my code:
it("should use function body as a string", function () {
var add = new Function("a", "b", "return a + b;");
expect(add(1, 2)).toBe(3);
var multiply = function (a, b) {
//An internal comment
return a * b;
};
var functionMultiply = "function (a, b) {\n\
//An internal comment\n\
return a * b;\n\
}"
expect(multiply.toString()).toBe(functionMultiply);
});
Could someone possibly help me with this one?
Here what works for me on Chrome 23:
it("should use function body as a string", function () {
var add = new Function("a", "b", "return a + b;");
expect(add(1, 2)).toBe(3);
var multiply = function (a, b) {
//An internal comment
return a * b;
};
expect(multiply.toString()).toBe("function (a, b) {\n"
+ " //An internal comment\n"
+ " return a * b;\n"
+ " }");
});
See also #10.
Wouldn't this work as well? "function(a, b) {" "// An internal comment" "return a * b;" "};"
var multiply = function (a, b) { //An internal comment return a * b; }; var stupid = "function (a, b) { \ return a * b; \ }" expect(multiply.toString()).toBe(stupid);
why doesn't that work? if i remove the '\' lien terminators it works but Firefox throws an unterminated string literal error.