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.
jest.mock('config')
mockConfigTtl = require('config').get.mockReturnValue(100);
mockConfigScheduling = require('config').get.mockReturnValue('* * * * *');
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:
jest.mock('config')
mockConfigTtl = require('config').get('firstKey').mockReturnValue(100);
mockConfigScheduling = require('config').get('secondKey').mockReturnValue('* * * * *');
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
mockReturnValueand execute your implementation.example:
or in case you want to test even more configuration you may use describe.each
which would generate a snapshot with the result form your implementation and if it changes the test will fail unless snapshot is updated