I have a test function that uses a file in the following path in my nestjs application:
/Users/username/Documents/projectname/src/assets/responses/message.hbs
This path is provided by a file service and is build from the application path, that is:
'application path'+'assets/responses/message.hbs'
However, my test module thinks the application path is the test file path, and when it calls the file service, the service returns the following path instead:
/Users/username/Documents/projectname/src/modules/session/assets/responses/message.hbs'
where modules/session/
is the path of my test file relative to src/
folder.
Is there a way to make jest think that my current test path is not /Users/username/Documents/projectname/src/modules/session/
but /Users/username/Documents/projectname/src/
?
Here is an example of how my test configuration looks like:
import { Test, TestingModule } from '@nestjs/testing';
import { Service } from './service.service';
import { FileHelperService } from '../../shared/modules/file-helper.service';
describe('Service', () => {
let service: Service;
beforeAll(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [
Service,
FileHelperService,
],
}).compile();
service = module.get<Service>(Service);
});
it('should compile', () => {
expect(service).toBeDefined();
describe('function that uses message.hbs', () => {
service.functionThatUsesFile();
});
});
What did you try and what were you expecting?
I’m running a test in this folder: /Users/username/Documents/projectname/src/modules/session/
, but I would like my testing module to think it is being run from the following folder: /Users/username/Documents/projectname/src/
.