Skip to content
Advertisement

mock node config with jest

I introduce myself currently for the first time in jest and nodejs. I am facing the problem that I have to mock two different values from the nodejs config.

JavaScript

the problem is that the second mockReturnValue overwrites the first one. is there any possibility to separate booth mocks from each other?

Maybe with something like:

JavaScript

Advertisement

Answer

Since you would want to ensure your implementation would work with all possible configuration I consider it best to set multiple test scenarios in different describe block and in each of them use mockReturnValue and execute your implementation.

example:

JavaScript

or in case you want to test even more configuration you may use describe.each

JavaScript

which would generate a snapshot with the result form your implementation and if it changes the test will fail unless snapshot is updated

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement