我正在尝试在 2 个摩卡测试文件之间连接对象。这是我的 test1.js 文件,一旦执行所有测试用例,该文件应该导出一个变量。
var assert = require('assert');
var newUser = {
email: "[email protected] /cdn-cgi/l/email-protection",
name: "[email protected] /cdn-cgi/l/email-protection",
password: "[email protected] /cdn-cgi/l/email-protection",
confirmPassword: "[email protected] /cdn-cgi/l/email-protection"
}
var studentAcademicData = {
marks: {},
activities: {}
}
var studentInterests = []
var testSummary = {},
loggedInUser = {},
avaialbleAssessment = {},
test = {},
interests = {};
var studentAcademicId, studentId, academicYearId, assessmentId, testId;
describe('perform functional Test', function() {
before(function() {
this.timeout(15000);
db.init(config.mongodb);
})
//Register a student it ('Register a student', function(done){
StudentController.register(newUser).then(function(data) {
assert.equal(data.name, newUser.name) assert.equal(data.tenant, newUser.tenant) assert.equal(data.customerType, newUser.customerType)
done();
}).catch(done)
});
//User authentication it ('Authenticates user', function(done){
var userInfo = {
appId: "abc",
email: newUser.email,
password: newUser.password
}
security.userAuthenticate(userInfo).then(function(data) {
securityToken = data.securityToken;
tenantId = data.tenantId;
emailStatus = data.emailStatus;
mobileStatus = data.mobileStatus studentId = data.userId;
done();
}).catch(done)
});
it('Gets Student by id', function(done) {
StudentController.getById(studentId).then(function(data) {
loggedInUser = data;
loggedInUser.tenantId = 'abc';
loggedInUser.userId = studentId;
loggedInUser.securityToken = securityToken;
done();
}).catch(done)
});
})
module.exports.testUser = {
loggedInUser: loggedInUser,
avaialbleAssessment: avaialbleAssessment,
interests: interests,
testSummary: testSummary,
studentAcademicData: studentAcademicData,
newUs
er: newUser,
test: test
};
这是我的 test2.file,它从 test1.js 文件导入对象
var assert = require('assert');
var rewire = require('rewire');
var TestUserObj = require('./test1');
describe('perform test2 Test', function() {
console.log("in test2")
console.log("TestUserObj ::::" + JSON.stringify(TestUserObj))
});
我在 test2.js 文件中得到的输出是
TestUserObj
::::{
"testUser": {
"loggedInUser": {},
"avaialbleAssessment": {},
"interests": {},
"testSummary": {},
"newUser": {
email: "[email protected] /cdn-cgi/l/email-protection",
name: "[email protected] /cdn-cgi/l/email-protection",
password: "[email protected] /cdn-cgi/l/email-protection",
confirmPassword: "tes[email protected] /cdn-cgi/l/email-protection"
},
"test": {}
}
}
导出的值不包含修改的对象