【发布时间】:2023-04-02 22:30:01
【问题描述】:
我正在努力将最佳实践付诸实践,将用于赛普拉斯测试的现有文件转换为更适合导出和导入的格式。
目前:
支持文件.js
export const1 = () => cy.get('#someId1');
export const2 = () => cy.get('#someId2');
export const3 = () => cy.get('#someId3');
export function myFunct1() {
// Do something
}
export function myFunct2() {
// Do something
}
export function myFunct3() {
// Do something
}
file-where-used.js
import {
const1, const2, const3,
myFunct1, myFunct2, myFunct3
}
// usage of the consts/functs below
我已经尝试过尝试将它们变成一种格式,这样我就不必单独导入每个,但我无法弄清楚......我想,也许将所有内容包装为一个类并导出它,这确实有效但仅在使用require 而不是import 时...而且我还发现导出我的const 变量有困难...
尝试
export const1 = () => cy.get('#someId1');
export const2 = () => cy.get('#someId2');
export const3 = () => cy.get('#someId3');
class myClass {
myFunct1() {
// Do something
}
myFunct2() {
// Do something
}
myFunct3() {
// Do something
}
}
module.exports = new myClass();
【问题讨论】:
标签: javascript node.js import export cypress