私はindex.htmlファイルに 'Hello world! H1で "テキスト:私はすべてを保存して、このようにそれを実行しJavaScript + Mocha + Chai。私のテストはいつも通り過ぎますか?
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\""
、それは常に報告します"合格"。
私もexpect
文字列をコメントすることができ、そしてそれはあなたがit
への引数としてdone
宣言する必要があまりにもオブジェクト指向
ああ...ありがとうございました!今それは魅力のように動作します! +私はまた、 'getElement_s_ByTagName'があるはずです:) –