Skip to content

Commit ef1e922

Browse files
committed
changed sinon.spy to use prototype
1 parent 3156e4b commit ef1e922

File tree

1 file changed

+11
-15
lines changed

1 file changed

+11
-15
lines changed

test/unit/operations/abstract_command.test.ts

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import {
55
type Callback,
66
type ClientSession,
77
CommandCallbackOperation,
8+
CommandOperation,
89
type CommandOperationOptions,
9-
type Document,
1010
type OperationParent,
1111
Server,
1212
ServerDescription
@@ -18,14 +18,6 @@ class ConcreteCommand<T> extends CommandCallbackOperation<T> {
1818
super(parent, options);
1919
}
2020

21-
async executeCommand(
22-
server: Server,
23-
session: ClientSession | undefined,
24-
cmd: Document
25-
): Promise<any> {
26-
return super.executeCommand(server, session, cmd);
27-
}
28-
2921
protected executeCallback(
3022
server: Server,
3123
session: ClientSession | undefined,
@@ -48,14 +40,18 @@ describe('class CommandOperation', () => {
4840
);
4941
});
5042

51-
context('when a server is created', () => {
52-
it('calls executeCommand, which calls server.commandAsync, when executeCommandCallback is invoked', async () => {
43+
context('when an operation uses CommandCallbackOperation', () => {
44+
it('calls executeCommand when executeCommandCallback is invoked', done => {
5345
const operation = new ConcreteCommand<any>();
54-
const serverSpy = sinon.stub(server, 'commandAsync');
55-
operation.executeCommandCallback(server, undefined, { ping: 1 }, (err, res) => {
56-
err ? err : res;
46+
const operationSpy = sinon.spy(CommandOperation.prototype, 'executeCommand');
47+
operation.executeCommandCallback(server, undefined, { ping: 1 }, () => {
48+
try {
49+
expect(operationSpy).to.have.been.calledOnceWithExactly(server, undefined, { ping: 1 });
50+
done();
51+
} catch (error) {
52+
done(error);
53+
}
5754
});
58-
expect(serverSpy).to.have.been.calledOnce;
5955
});
6056
});
6157
});

0 commit comments

Comments
 (0)