Skip to content

Commit 0da3480

Browse files
tests(@nestjs) fix broken stubs, flush out exceptions
1 parent 64629cf commit 0da3480

5 files changed

Lines changed: 20 additions & 20 deletions

File tree

packages/core/test/guards/guards-consumer.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@ describe('GuardsConsumer', () => {
4949
});
5050
describe('pickResult', () => {
5151
describe('when result is Observable', () => {
52-
it('should returns promise', () => {
52+
it('should returns result', async () => {
5353
expect(
54-
consumer.pickResult(of(true)),
55-
).to.eventually.instanceOf(Promise);
54+
await consumer.pickResult(of(true)),
55+
).to.be.true;
5656
});
5757
});
5858
describe('when result is Promise', () => {

packages/core/test/helpers/external-context-creator.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ describe('ExternalContextCreator', () => {
5757
describe('when can not activate', () => {
5858
it('should throw exception when "tryActivate" returns false', () => {
5959
sinon.stub(guardsConsumer, 'tryActivate', () => false);
60-
expect(proxyContext(1, 2, 3)).to.eventually.throw();
60+
expect(proxyContext(1, 2, 3)).to.eventually.throw;
6161
});
6262
});
6363
describe('when can activate', () => {
@@ -86,7 +86,7 @@ describe('ExternalContextCreator', () => {
8686

8787
modules.set(moduleKey, {});
8888
(contextCreator as any).modulesContainer = modules;
89-
sinon.stub(contextCreator, 'findComponentByClassName', () => true);
89+
sinon.stub(contextCreator, 'findComponentByClassName').callsFake(() => true);
9090

9191
expect(
9292
contextCreator.findContextModuleName({ name: componentKey } as any),
@@ -95,7 +95,7 @@ describe('ExternalContextCreator', () => {
9595
});
9696
describe('when component does not exists', () => {
9797
it('should return empty string', () => {
98-
sinon.stub(contextCreator, 'findComponentByClassName', () => false);
98+
sinon.stub(contextCreator, 'findComponentByClassName').callsFake(() => false);
9999
expect(contextCreator.findContextModuleName({} as any)).to.be.eql('');
100100
});
101101
});

packages/core/test/router/router-execution-context.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ describe('RouterExecutionContext', () => {
117117
});
118118
});
119119
it('should throw exception when "tryActivate" returns false', () => {
120-
sinon.stub(guardsConsumer, 'tryActivate', () => false);
120+
sinon.stub(guardsConsumer, 'tryActivate').callsFake(() => false);
121121
expect(proxyContext(request, response, next)).to.eventually.throw();
122122
});
123123
});
@@ -326,7 +326,7 @@ describe('RouterExecutionContext', () => {
326326
describe('createGuardsFn', () => {
327327
it('should throw exception when "tryActivate" returns false', () => {
328328
const guardsFn = contextCreator.createGuardsFn([null], null, null);
329-
sinon.stub(guardsConsumer, 'tryActivate', () => false);
329+
sinon.stub(guardsConsumer, 'tryActivate').callsFake(() => false);
330330
expect(guardsFn([])).to.eventually.throw();
331331
});
332332
});

packages/microservices/test/server/server-mqtt.spec.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,11 @@ describe('ServerMqtt', () => {
7676
});
7777
describe('handler', () => {
7878
it('should call "handleMessage"', async () => {
79-
const spy = sinon.spy(server, 'handleMessage');
79+
const handleMessageStub = sinon
80+
.stub(server, 'handleMessage')
81+
.callsFake(() => null);
8082
(await server.getMessageHandler((server as any).mqttClient))(null);
81-
expect(spy.called).to.be.true;
83+
expect(handleMessageStub.called).to.be.true;
8284
});
8385
});
8486
});

packages/microservices/test/server/server-nats.spec.ts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,12 @@ describe('ServerNats', () => {
7373
});
7474
describe('handler', () => {
7575
it('should call "handleMessage"', async () => {
76-
const spy = sinon.spy(server, 'handleMessage');
77-
(await server.getMessageHandler(null, (server as any).natsClient))(null);
78-
expect(spy.called).to.be.true;
79-
})
76+
const handleMessageStub = sinon
77+
.stub(server, 'handleMessage')
78+
.callsFake(() => null);
79+
(await server.getMessageHandler('', (server as any).natsClient))('');
80+
expect(handleMessageStub.called).to.be.true;
81+
});
8082
});
8183
});
8284
describe('handleMessage', () => {
@@ -130,12 +132,8 @@ describe('ServerNats', () => {
130132
it(`should call "publish" with expected arguments`, () => {
131133
const respond = 'test';
132134
publisher({ respond, id });
133-
expect(
134-
publisherSpy.calledWith(
135-
`${pattern}_res`,
136-
{ respond, id },
137-
),
138-
).to.be.true;
135+
expect(publisherSpy.calledWith(`${pattern}_res`, { respond, id })).to.be
136+
.true;
139137
});
140138
});
141139
describe('getAckPatternName', () => {

0 commit comments

Comments
 (0)