简体   繁体   English

Mocha / Chai测试linkTo函数返回AssertionError

[英]Mocha/Chai Test linkTo Function Returning AssertionError

I'm trying to find & correct the Javascript code in challenge.js so that it passes the Mocha & Chai tests as specified in spec.js .... Nothing I try will get it to pass the tests when I run the command $ mocha spec.js in the Terminal.... To provide more information, the resulting error message that is continually returned in the Terminal regardless of any changes I make to challenge.js is shown underneath. 我试图在Challenge.js中查找并更正Javascript代码,以使其通过spec.js中指定的Mocha&Chai测试……。当我运行命令$ mocha spec.js时,我没有尝试通过测试终端中的$ mocha spec.js 。...为了提供更多信息,无论我对Challenge.js进行的任何更改如何,在终端中不断返回的结果错误消息将显示在下面。

Challenge.js Challenge.js

module.exports.linkTo = function(text, address) {   
  return "<a href='" + text + "'>" + address + "</a>"
};

Spec.js 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>");
  });
});

Error Message as returned in Terminal 在终端中返回的错误消息

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)

Can anyone PLEASE point out the correction(s) needed in challenge.js in order for the tests to pass when I run $ mocha spec.js in the Terminal??? 任何人都可以指出在Challenge.js中所需的更正,以便在终端中运行$ mocha spec.js时才能通过测试$ mocha spec.js

Thanks in advance Lex 预先感谢Lex

Replace adress with text and text with address inside function declaration. 在函数声明中用文本替换地址,并用地址替换文本。

module.exports.linkTo = function(text, address) {   
  return "<a href='" + address + "'>" + text + "</a>"
};

Test output cleary says what was expected 测试输出明确说明了预期的结果

+<a href='http://www.bloc.io'>Bloc</a>
-<a href='Bloc'>http://www.bloc.io</a>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM