0
我有几个方法设置文本文件内的文本。为什么我无法测试文本文件的文本?
在我运行测试之前,我已经设置了我的茉莉花测试以创建具有错误值的文件。
var gpioPath = 'tests/gpio-test/class/gpio';
//setup the filesystem with the exports path
fs.outputFileSync(gpioPath+'/export',0);
for(var i=0;i<6;i++){
fs.outputFileSync(gpioPath+i+'/value',2,'utf-8');
fs.outputFileSync(gpioPath+i+'/direction','none','utf-8');
}
然后,我运行更新文件中的值的方法,然后检查文件现在是否具有正确的值。
expect(fs.readFileSync(gpioPath+'/export','utf-8')).toBeGreaterThan(0);
var pin1d = fs.readFileSync(gpioPath+'1/direction','utf-8');
var pin1v = fs.readFileSync(gpioPath+'1/value','utf-8');
expect(pin1d).toBe('out');
expect(pin1v).toBe(0);
由于某些原因,这些测试都失败了。我得到
'0' expected to be greater than '0'
但是,当我看到在该文件中,我有6
我试图把一个值waits
再运行测试,以防万一这些文件没有被改变但是,即使等待10秒钟,这仍然是失败的。
我没有从fileWrite方法得到任何错误,它是什么更新数据,正如我所说,我可以看到该文件已更新,所以为什么我的测试不反映这个?
你是对的字符串整数转换,但我仍然没有从readFile获取更新的值。正如我所提到的,我可以看到该值为5,但测试显示“期望0大于0”。奇怪。 – pedalpete
@pedalpete你在做什么来看'5'? 'cat'?一个文本编辑器? – loganfsmyth
当我在我的文本编辑器中打开文件时,我看到了5. – pedalpete