How to extend Mocha's Context interface?

后端 未结 1 1978
半阙折子戏
半阙折子戏 2020-12-22 07:47

Take the following code snippet:

import { Foo } from \"./foo\";

export interface MyContext extends Mocha.Context {
  foo: Foo;
}

This is i

相关标签:
1条回答
  • 2020-12-22 08:44

    Literally extending mocha's Context type using that derived interface is not what you want to do here. Instead, you want to augment the type defined by the library, adding your member.

    This can be accomplished as follows:

    // augmentations.d.ts
    import {Foo} from './foo';
    
    declare module "mocha" {
      export interface Context {
        foo: Foo;
      }
    }
    

    Example usage:

    describe("my test suite", function() {
      it("should do something", function() {
        console.log(this.foo);
      });
    });
    
    0 讨论(0)
提交回复
热议问题