我想测试要测试的函数中的构造函数是否使用正确的参数调用,我的示例如下:
我有一个课程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');
});
});
您不能