Skip to content

Commit

Permalink
test(module): update app.service.spec and delegator spec to uvu
Browse files Browse the repository at this point in the history
  • Loading branch information
jmcdo29 committed Feb 23, 2022
1 parent 2aaf242 commit 8ee7443
Show file tree
Hide file tree
Showing 4 changed files with 166 additions and 244 deletions.
9 changes: 5 additions & 4 deletions .swcrc
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@
"legacyDecorator": true,
"decoratorMetadata": true
},
"target": "es2017",
"keepClassNames": true,
"baseUrl": ".",
"paths": {
"@ogma/*": [
"packages/*/src/"
]
"@ogma/*": ["packages/*/src/"]
}
},
"module": {
"type": "commonjs"
"type": "commonjs",
"strictMode": true
}
}
46 changes: 25 additions & 21 deletions packages/nestjs-module/test/app.service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,36 +1,40 @@
import { AppService } from './app.service';
import { Test } from '@nestjs/testing';
import { spy, Stub } from 'hanbi';
import { suite } from 'uvu';
import { equal, ok } from 'uvu/assert';

describe('AppService', () => {
let service: AppService;
let logger: { log: jest.Mock };

beforeEach(async () => {
const AppServiceSuite = suite<{ service: AppService; logSpy: Stub<(message: string) => void> }>(
'AppService',
{
service: undefined,
logSpy: spy(),
},
);
AppServiceSuite.before(async (context) => {
try {
const modRef = await Test.createTestingModule({
providers: [
AppService,
{
provide: 'OGMA_SERVICE:AppService',
useValue: {
log: jest.fn(),
log: context.logSpy.handler,
},
},
],
}).compile();
service = modRef.get(AppService);
logger = modRef.get<{ log: jest.Mock }>('OGMA_SERVICE:AppService');
});

it('should be truthy', () => {
expect(service).toBeTruthy();
});

it('should return { hello: world }', () => {
expect(service.getHello()).toEqual({ hello: 'world' });
expect(logger.log).toHaveBeenCalledWith('Say Hello');
});
context.service = modRef.get(AppService);
} catch (err) {
console.error(err);
}
});

process.on('unhandledRejection', (err) => {
throw new Error(err as any);
AppServiceSuite('it should create the service', ({ service }) => {
ok(service);
});
AppServiceSuite('It should return { hello: world } and log "Say Hello"', ({ service, logSpy }) => {
equal(service.getHello(), { hello: 'world' });
ok(logSpy.calledWith('Say Hello'));
});

AppServiceSuite.run();
2 changes: 1 addition & 1 deletion packages/nestjs-module/test/app.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { OgmaLogger, OgmaService } from '../src';

@Injectable()
export class AppService {
constructor(@OgmaLogger(AppService) private readonly logger: OgmaService) {}
constructor(@OgmaLogger('AppService') private readonly logger: OgmaService) {}

getHello() {
this.logger.log('Say Hello');
Expand Down
Loading

0 comments on commit 8ee7443

Please sign in to comment.