我正在尝试查找&更正challenge.js中的Javascript代码,使其通过Mocha&Chai按照spec.js中的规定进行测试……当我在终端中运行命令$ mocha spec.js
时,我所做的任何尝试都无法使它通过测试。。。。为了提供更多信息,无论我对challenge.js做了什么更改,终端都会不断返回错误消息。
挑战.js
module.exports.linkTo = function(text, address) {
return "<a href='" + text + "'>" + address + "</a>"
};
Spec.js
var expect = require("chai").expect;
var challenge = require("./challenge.js");
describe("linkTo", function() {
it("should be defined", function() {
expect(challenge.linkTo).to.exist;
});
it("should return a valid link for Bloc", function() {
expect(challenge.linkTo("Bloc", "http://www.bloc.io")).to.eql("<a href='http://www.bloc.io'>Bloc</a>");
});
});
终端返回的错误消息
linkTo
✓ should be defined
1) should return a valid link for Bloc
1 passing (11ms)
1 failing
1) linkTo should return a valid link for Bloc:
AssertionError: expected '<a href='Bloc'>http://www.bloc.io</a>' to deeply equal '<a href='http://www.bloc.io'>Bloc</a>'
+ expected - actual
+<a href='http://www.bloc.io'>Bloc</a>
-<a href='Bloc'>http://www.bloc.io</a>
at Context.<anonymous> (/home/vagrant/frontend-javascript-exercises/02-reading-mocha-tests/00-a-tested-function/spec.js:10:63)
at callFn (/usr/local/lib/node_modules/mocha/lib/runnable.js:266:21)
at Test.Runnable.run (/usr/local/lib/node_modules/mocha/lib/runnable.js:259:7)
at Runner.runTest (/usr/local/lib/node_modules/mocha/lib/runner.js:387:10)
at /usr/local/lib/node_modules/mocha/lib/runner.js:470:12
at next (/usr/local/lib/node_modules/mocha/lib/runner.js:312:14)
at /usr/local/lib/node_modules/mocha/lib/runner.js:322:7
at next (/usr/local/lib/node_modules/mocha/lib/runner.js:257:23)
at Object._onImmediate (/usr/local/lib/node_modules/mocha/lib/runner.js:289:5)
at processImmediate [as _immediateCallback] (timers.js:336:15)
当我在终端中运行$ mocha spec.js
时,有人能指出challenge.js中需要的更正吗???
提前感谢Lex
在函数声明中用文本替换地址,用地址替换文本。
module.exports.linkTo = function(text, address) {
return "<a href='" + address + "'>" + text + "</a>"
};
测试输出清楚地说明了预期的
+<a href='http://www.bloc.io'>Bloc</a>
-<a href='Bloc'>http://www.bloc.io</a>