Skip to main content
100%

testing, moudle mocking.

✓ Published0🌍 Public
NNikhilkuyya
Last edited Nov 6, 2018
Created on Nov 6, 2018

This example demonstrates how to mock an ES module dependency using Node’s `require.cache` to simulate a custom module cache. It builds a manual mock function with a call tracker and mock implementation for `utils.getWinner`, then injects it into the cache before requiring the `thumb-war` module. The test verifies the mocked function’s call arguments and returns a deterministic winner, followed by cache cleanup. The code uses `require.resolve`, `require.cache`, and `assert.deepStrictEqual` to validate mock behavior.

AI-generated description

Similar vizzes