Skip to content

Commit feaf750

Browse files
Merge pull request nestjs#3592 from tonyhallett/external-context-creator-expect-in-catch
test(core): fix expectation in catch
2 parents 424da09 + c28eddf commit feaf750

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

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

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ describe('ExternalContextCreator', () => {
2222
let applySpy: sinon.SinonSpy;
2323
let guardsConsumer: GuardsConsumer;
2424
let pipesConsumer: PipesConsumer;
25+
let guardsContextCreator: GuardsContextCreator;
2526

2627
beforeEach(() => {
2728
callback = {
@@ -33,8 +34,10 @@ describe('ExternalContextCreator', () => {
3334

3435
guardsConsumer = new GuardsConsumer();
3536
pipesConsumer = new PipesConsumer();
37+
guardsContextCreator = new GuardsContextCreator(new NestContainer());
38+
sinon.stub(guardsContextCreator, 'create').returns([{}] as any);
3639
contextCreator = new ExternalContextCreator(
37-
new GuardsContextCreator(new NestContainer()),
40+
guardsContextCreator,
3841
guardsConsumer,
3942
new InterceptorsContextCreator(new NestContainer()),
4043
new InterceptorsConsumer(),
@@ -73,11 +76,17 @@ describe('ExternalContextCreator', () => {
7376
});
7477
describe('when proxy function called', () => {
7578
describe('when can not activate', () => {
76-
it('should throw exception when "tryActivate" returns false', () => {
79+
it('should throw exception when "tryActivate" returns false', async () => {
7780
sinon
7881
.stub(guardsConsumer, 'tryActivate')
7982
.callsFake(async () => false);
80-
proxyContext(1, 2, 3).catch(err => expect(err).to.not.be.undefined);
83+
let err: any;
84+
try {
85+
await proxyContext(1, 2, 3);
86+
} catch (e) {
87+
err = e;
88+
}
89+
expect(err).to.be.undefined;
8190
});
8291
});
8392
describe('when can activate', () => {

0 commit comments

Comments
 (0)