dimanche 1 mars 2020

How to test function that changes file content (Jest)

For example i have a function in module "updater.js" that changes "main.js" file content, how i can test this behavior with jest?

Updater function code:

function update() {
  ..... update main.js content
}

module.exports = update

Project structure:

myProject
  updater.js
  main.js <-this file changes if call "update" function

I want to place the "main.js" test file in "fixtures" folder, then, during testing, i want to copy this file to some "tmp" directory, run my function (updater.js) on this file, and at the end of testing delete "tmp" folder, which contains changed "main.js". How to realize this with Jest? P.S Excuse me for my English :)

Aucun commentaire:

Enregistrer un commentaire