mercredi 18 mars 2020

I am using jest to test a function which uses an environment variable but not in the test itself, is it possible to mock it?

test.spec.js

it('mock environment variables is used in function', ()=> {
  expect(useEnvVarInFunc()).toBe('abc') //fails when I want to pass
})

func.js

function useEnvVarInFunc() {
  const { api_key } = process.env
  return api_key
}

.env

api_key = '123'

So I have something like this. I want to be able to hopefully have a jest global mock variables for the all jest tests I run. If there's any work around I can do Please let me know (: thank you

Aucun commentaire:

Enregistrer un commentaire