I'm a Java Developer but I want to have some experience also with NodeJS. In Java, when i make a function, then i can run this function in a simple way with using tests like below:
@Autowired
SomeService service;
@Test
public void testGet() {
SomeDto dto = service.getDto(1L);
log.info("Retrieved: {}", dto.getName());
}
Right now I can run only this one test and check that my method work properly. But how to do this with using NodeJS? For example i have this method:
async getData(id: any): Promise<SomeDto> {
return this.conn.getRepository(Client).findById(id);
}
how to run this method in tests like I'm doing it with Java?
PS. I don't want to create unit test and so on, I want only to run my functions with using tests
thanks for any help!
In nodejs (Or TS) we have lot of test framework, mocha is famous test framework
You can use mocha for BDD, TDD, ...
See mocha document in https://mochajs.org/
Below link help you to write test in nodejs and i hope helpful for you:
https://blog.logrocket.com/a-quick-and-complete-guide-to-mocha-testing-d0e0ea09f09d/
Tip: If you want use TDD you can use sinon package, this package is so good for TDD and fake function