Я использую jest с очень простым поиском в текстовом файле, но мой тест jest никогда не проходил, и я не уверен, что я делаю здесь неправильно, я также пытался с toBe
, и я все еще получаю та же ошибка.
Вот мой код:
const fs = require('fs');
const path = require('path');
var isFound = false;
test("searching in file", () => {
// actual test
fs.readFile(__dirname+'/files/test.txt', "utf8", (err, data) => {
if (err) throw err;
const fileStream = data.toLowerCase();
if(fileStream.includes('awesome')){
//console.log('found in file');
isFound = true;
} else {
isFound = false;
//console.log('not found in file');
}
})
expect(isFound).toEqual(true);
});
ОШИБКА:
18 | })
19 | //expect(found).toEqual(true);
> 20 | expect(isFound).toEqual(true);
| ^
21 |
22 |
23 | });