gpt4 book ai didi

jquery - jest.js 中的 loadFixtures 方法

转载 作者:行者123 更新时间:2023-12-04 17:51:18 26 4
gpt4 key购买 nike

jest 中是否有与 loadFixtures 方法等效的方法。我似乎在 Jest 文档中找不到任何内容。我希望能够将 html 固定装置加载到 jest 测试文件中?

或者有没有另一种方法可对于Jest地做 html stub 我错过了?

请注意,我没有将 React 用作​​ Jquery 的旧项目。

所以,而不是写一些类似的东西。

window.$ = require('jquery');

beforeEach(() => {


document.body.innerHTML =
'<div>' +
' <input id="exMonth" value="02" />' +
' <input id="exYear" value="2017" />'
'</div>';

});


test("exMonth should be 02", () =>{

expect($('#exMonth').val()).toBe('01');

});

我想将我的 html 抽象为一个 html 固定文件并要求它
document.body.innerHTML = require(myHtmlFixture.html)

最佳答案

您可以使用节点的 fs用于服务器端测试。

var fs = require('fs');

var htmlFixture = fs.readFileSync('spec/fixtures/myFixture.html')

document.body.innerHTML = htmlFixture;
见: https://nodejs.dev/learn/reading-files-with-nodejs

关于jquery - jest.js 中的 loadFixtures 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44548730/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com