A
A
Andrey Prozorov2019-05-09 18:35:34
JavaScript
Andrey Prozorov, 2019-05-09 18:35:34

How to properly test a class using a helper?

The class uses Helper.queryToUrl(param) those static method.
This is how the method I'm testing looks like

public findExtendedByQueryObject(queryObject: object): Promise<SearchResult> {
    const queryString = Helpers.queryToUrl(queryObject);
    return this.find(`/organizations/?${queryString}`);
  }

During the test, the helper function dies. Why she dies is a separate question. My question is that, in general, am I doing the testing correctly? Maybe I need to replace the hepler class in static form with DI so that I can wet it? Or are there other ways to mokat this thing? Or am I doing everything right, only I need to write tests for the helper class first.
Sorry for the noob question..

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir, 2019-05-09
@i_d_1

Helpers.queryToUrl definitely needs to be mocked, in the simplest case it is
const Helpers = {queryToUrl:()=>{}}
In general, you need to read the documentation of the framework you use for testing.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question