Closed dbmundell closed 4 years ago
There is nothing wrong at mock-fs side. You probably has code to trigger that error after reading file content.
Following code runs as expected.
const fs = require('fs');
const mockfs = require('mock-fs');
mockfs({
"something": "ONE-THING\tANOTHER "
});
const content = fs.readFileSync('something', 'utf8');
console.log(content);
Note if you write the file content in code, you have to escape \
for the json file.
mockfs({
"a.json": `{"something":"ONE-THING\\tANOTHER "}`
});
Because in json file, you need literally two characters: \
and t
. If you write \t
inside js code string, it becomes only one character (the tab character), not two.
When loading a JSON formatted fake file like this:
{ "something": "ONE-THING\tANOTHER " }
I get an error saying that an unexpected character was found - removing \t successfully loads the file