reactjs - 用于范围外变量的 Flux Store 的 JEST 规范
问题描述
我正在尝试为基于 Flux 的商店编写规范。组件外部定义了一些变量,这些变量在组件内部使用。当我尝试为它创建模拟时,它并没有捡起它。
员工商店
let employee_year = null;
let all_employees = [];
const dropdown = document.getElementById('employee_projects'); //This is the not the react component.
if (dropdown) { employee = dropdown.options[dropdown.selectedIndex].getAttribute('employee_year_id'); }
if (window.VIEW_DATA.all_employees) { all_employees= JSON.parse(window.VIEW_DATA.all_employees); }
const viewData = JSON.parseJSON({
employee_details: all_employees.filter(e => e[employee_year])[0],
employee_year: employee_year
});
class EmployeeStore extends Store { //Flux Store
{
const employeeDetails = all_employees[employee_year] || [];
const relatedDetails = employeeDetails.filter(e => e.type === 'Permanent');
}
JEST 规格
describe('EmployeeStore', () => {
beforeAll(() => {
global.employee_year = 2019; //Not sure of this syntax
window.VIEW_DATA.all_employees = [
'employee_1': {}
'employee_2': {}
];
dd = window.document.createElement('select');
const option = window.document.createElement('option');
option.setAttribute('employee_year_id', 2019);
dd.appendChild(option);
spyOn(window.document, 'getElementById').and.returnValue(dd);
});
});
我得到的一切都是undefined
我设定的beforeAll
。有任何想法吗?
解决方案
推荐阅读
- r - 使用 R 计算单词的频率及其出现在哪一列
- java - 握手方的递归调用
- java - 一页上实体实例的多种形式 - 未创建表单
- css - Vuetify 主题不适用于自定义主题
- c# - 来自 C# 的 LSP 悬停文本降价链接不起作用
- command-line-interface - Zapier CLI,有没有办法改变输出的显示顺序
- ubuntu - xfce4 via VcXsrv Server on wsl2 与 DPI 问题
- python - 如何在 3D 阵列的特定一侧应用 2D 蒙版?
- swiftui - SwiftUI - 将项目从一个列表拖到另一个
- python - 将 if 语句条件与用户输入语句匹配(减少多个条件)