Javascript:Jasmine错误:预期{0:HTMLNode,长度:1}为'#集装箱';

Javascript:Jasmine错误:预期{0:HTMLNode,长度:1}为'#集装箱';,javascript,jasmine,Javascript,Jasmine,我花了很长时间试图解决这个问题。任何人都可以帮我解决这个问题 我正是在这个youtube教程下面: 当我完成输入时: describe("Experimentation", function() { var elem; beforeEach(function() { elem = $('<div id="container"><p>Hello World</p></div>'); }); it("allows us to search

我花了很长时间试图解决这个问题。任何人都可以帮我解决这个问题

我正是在这个youtube教程下面:

当我完成输入时:

describe("Experimentation", function() {
var elem;

beforeEach(function() {
    elem = $('<div id="container"><p>Hello World</p></div>');
});

it("allows us to search with CSS selectors", function() {
    expect(elem).toBe('#containers');    // Problem happened here!!!!!!!
});});
描述(“实验”,函数(){
var-elem;
beforeach(函数(){
元素=$(“你好,世界”

”); }); 它(“允许我们使用CSS选择器进行搜索”,函数(){ expect(elem).toBe(“#containers”);//这里发生了问题!!!!!!! });});
输出结果:

Experimentation allows us to search with CSS selectors
Expected { 0 : HTMLNode, length : 1 } to be '#containers'.
Error: Expected { 0 : HTMLNode, length : 1 } to be '#containers'.
    at stack (http://localhost:8888/__jasmine__/jasmine.js:1293:17)
    at buildExpectationResult (http://localhost:8888/__jasmine__/jasmine.js:1270:14)
    at Spec.Env.expectationResultFactory (http://localhost:8888/__jasmine__/jasmine.js:484:18)
    at Spec.addExpectationResult (http://localhost:8888/__jasmine__/jasmine.js:260:46)
    at Expectation.addExpectationResult (http://localhost:8888/__jasmine__/jasmine.js:442:21)
    at Expectation.toBe (http://localhost:8888/__jasmine__/jasmine.js:1209:12)
    at Object.<anonymous> (http://localhost:8888/__spec__/experimentationSpec.js:9:16)
    at attemptSync (http://localhost:8888/__jasmine__/jasmine.js:1510:12)
    at QueueRunner.run (http://localhost:8888/__jasmine__/jasmine.js:1498:9)
    at QueueRunner.execute (http://localhost:8888/__jasmine__/jasmine.js:1485:10)
实验允许我们使用CSS选择器进行搜索
应将{0:HTMLNode,长度:1}作为“#容器”。
错误:应将{0:HTMLNode,长度:1}作为“#容器”。
堆叠(http://localhost:8888/__jasmine__/jasmine.js:1293:17)
在buildExpectationResult(http://localhost:8888/__jasmine__/jasmine.js:1270:14)
在Spec.Env.expectationResultFactory(http://localhost:8888/__jasmine__/jasmine.js:484:18)
按规格添加预期结果(http://localhost:8888/__jasmine__/jasmine.js:260:46)
at expection.addExpectationResult(http://localhost:8888/__jasmine__/jasmine.js:442:21)
期待中的托比(http://localhost:8888/__jasmine__/jasmine.js:1209:12)
反对。(http://localhost:8888/__spec__/experimentationSpec.js:9:16)
尝试同步(http://localhost:8888/__jasmine__/jasmine.js:1510:12)
在QueueRunner.run(http://localhost:8888/__jasmine__/jasmine.js:1498:9)
在QueueRunner.execute(http://localhost:8888/__jasmine__/jasmine.js:1485:10)
elem=$(“helloworld

”); expect(elem).toBe(“#容器”);
您正在将容器与容器进行比较。请注意额外的“s”。

elem=$(“helloworld

”); expect(elem).toBe(“#容器”);

您正在将容器与容器进行比较。请注意额外的“s”。

如果在将问题从#containers更改为#container之后仍然存在问题,请尝试将函数toBe()更改为toBeMatchedBy()。
我对#container也有同样的问题,通过更改函数,它起到了作用。

如果在将#containers更改为#container之后仍然存在问题,请尝试将函数toBe()更改为toBeMatchedBy()。
我对#container也有同样的问题,通过更改函数,它起了作用。

是因为传递给
expect
的HTML字符串是
#container
而不是
#containers
?是因为传递给
expect
的HTML字符串是
#container
而不是
#containers
elem = $('<div id="container"><p>Hello World</p></div>');

expect(elem).toBe('#containers');