tschaub / mock-fs

Configurable mock for the fs module
https://npmjs.org/package/mock-fs
Other
911 stars 86 forks source link

Reading from a file which I write to the mocked fs #283

Open brucebrit opened 5 years ago

brucebrit commented 5 years ago

Hi,

I am writing a unit testing using jasmine on an application (an electron + angular). Below shows partial code in the unit test

      const service: FileIntegrityService = TestBed.get(FileIntegrityService);
        mockFs({
          'G:/':{}
        })
        service.saveContentToFileSync("Hello World", "G:/me.txt")

        console.log(fs.readFileSync("G:/me.txt","utf-8"))   //The console log empty string, instead of "Hello World"

Inside the FileIntegrityService

   saveContentToFileSync(content: string, savePath: string): void {

             fs.writeFileSync(savePath,content)

  }

My query is why console.log show empty string?

brucebrit commented 4 years ago

hi, anyone?

challet commented 4 years ago

Maybe try to remove the G:.