我同意你应该
expect(c).toBe(...)
.还有一些其他的事情要小心。我会把你想要的方法放在
it
A块
beforeAll
或
beforeEach
方法以确保它们在IT块之前执行。
在清理它的同时,@jornsharpe的评论,我将执行以下操作:
const fs = require('fs');
const studentData = 'StudentData.json';
describe('Test for Json Data', () => {
const data = {
a: 'a',
b: 'bb',
c: 'ccc'
};
beforeAll(() => {
// make sure that you specify this in beforeAll or beforeEach
fs.writeFileSync(studentData ,JSON.stringify(data))
});
it('test for C', () => {
const uploadedData = fs.readFileSync(StudentData);
const parsedData = JSON.parse(uploadedData);
const c = parsedData['c'];
console.log(c);
expect(c)toBe('ccc'));
});
});