• Robert Knight's avatar
    Modify a mocking idiom that doesn't work with ES modules · 426d2670
    Robert Knight authored
    We have an idiom in many tests where we import the "default export" from
    a module and then access the `$imports` property on that
    function/class/object in order to mock or unmock imports. For example:
    
    ```
    const Widget = require('../widget');
    
    beforeEach(() => {
      Widget.$imports.$mock(...);
    });
    
    afterEach(() => {
      Widget.$imports.$restore();
    });
    ```
    
    This won't work when the module under test is converted to an ES module
    because the `$imports` object will become a separate export from the
    module rather than a property of the default export.
    426d2670
annotation-header-test.js 5.23 KB