通过Typescript和Sinon传递给构造函数的单元测试参数

问题描述 投票:0回答:1

我想测试要测试的函数中的构造函数是否使用正确的参数调用,我的示例如下:

我有一个课程Foo

export class Foo {

    constructor(param: string) {
    }
}

构造bar()的函数Foo

import { Foo } from './foo';

export function bar() {
    const foo = new Foo('test');

    // do some stuff with foo
}

以及测试功能bar()的单元测试:

import { expect } from 'chai';
import sinon from 'ts-sinon';
import { bar } from '../src/bar';

describe('bar', () => {

    beforeEach(() => {
    });

    it('should call foo with correct parameters', async () => {
        bar();
        // TODO: Something like this must work:
        // expect(fooStub).calledOnceWithExactly('test');
    });
});
typescript sinon
1个回答
1
投票

不能

© www.soinside.com 2019 - 2024. All rights reserved.