index.html 파일에 'Hello world! H1에서 '텍스트 : 나는 모든을 저장하고 다음과 같이 실행자바 스크립트 + 모카 + 차이. 왜 내 검사는 항상 통과합니까?
import {expect} from 'chai';
import jsdom from 'jsdom';
import fs from 'fs';
describe('index.html',() => {
it("should say 'Hello world!'",() => {
// read file content to variable
const index = fs.readFileSync('./src/index.html', "utf-8");
// pass this variable to jsdom:
jsdom.env(index, function(err, window) {
const h1 = window.document.getElementByTagName('h1')[0]; // read our h1
expect(h1.innerHTML).to.equal("Helloooooooo World!"); //<---- passed
done();
window.close();
});
})
})
: 여기
<!DOCTYPE HTML>
<html>
<head>
<title></title>
<meta charset="UTF-8">
</head>
<body>
<h1>Hello world!</h1>
<script src="bundle.js"></script>
</body>
</html>
및 내 index.test.js입니다
"test": "mocha --reporter progress buildScripts/testSetup.js \"src/**/*.test.js\""
과 항상보고 "합격".
OO
아 .. 당신을 감사합니다! 이제 그것은 매력처럼 작동합니다! + 나는 또한 'getElement_s_ByTagName'이 있어야한다는 것을 발견했습니다. :) –