V
V
Vadim2018-07-03 09:21:34
JavaScript
Vadim, 2018-07-03 09:21:34

When trying to find a file when running tests for karma and jasmine, it says fs.readFile is not a function, why is that?

Good afternoon, you need to write a function that takes a zip archive as a parameter, as well as write tests for karma and jasmine. The problem is that when I run tests and I want my file search function (it is needed only for tests) to find my test file and after passing it to my function in which I will work with this file, it falls.
Test file code:

const fs = require('fs');
const JSZip = require("jszip");

const searchfile = () => {


    fs.readFile('./data/2-11253540.zip', function (err, data) {
        if (err) throw err;
        JSZip.loadAsync(data).then(function (zip) {
            console.log('Process Zip: ', zip);
        });
    });

};

describe('Process', () => {

    const process = require('./process');
    searchfile();
    it('001', () => expect(process()).toEqual(null));

});


the searchfile error code should find the file and return it (yes, now it says something else, but it’s just to check if it works at all or not), and process should get this file. But when executed, I get that fs.readFile is not a function, or what is on the screen. Why does it crash and fs.readFile doesn't work?.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladlen Hellsite, 2018-07-03
@Darseed

Your browser does not have the fs module as it is only found in the node.js environment.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question