我花了很长时间试图解决这个问题。任何人都可以帮我解决这个问题。
我完全按照这个 YouTube 教程进行操作: http://www.youtube.com/watch?v=3Huh44nsZTw
当我完成输入时:
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!!!!!!!
});});
输出结果:
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)
最佳答案
elem = $('<div id="container"><p>Hello World</p></div>');
expect(elem).toBe('#containers');
您正在将容器与容器进行比较。请注意额外的“s”。
关于JavaScript:Jasmine 错误:预期 { 0 : HTMLNode, length : 1 } 为 '#containers',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24845610/