Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

190
Visualizações
QUnit - Testing functions of files besides formatter.js

The example given by UI5 of testing the formatter functions i.e.

// Assert
assert.strictEqual(fnIsolatedFormatter("A"), "New", "The long text for status A is correct");
assert.strictEqual(fnIsolatedFormatter("B"), "In Progress", "The long text for status B is correct");
assert.strictEqual(fnIsolatedFormatter("C"), "Done", "The long text for status C is correct");
assert.strictEqual(fnIsolatedFormatter("Foo"), "Foo", "The long text for status Foo is correct");

Works out very well, however, the same testing applied to functions of a controller file i.e. Example.controller.js, produces an error.

By trying to test the _onTestFunction of the Example.controller i do get the following error:

TypeError: Example._onTestFunction is not a function

Question: How do i test functions of a controller file that isn't formatter ?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

To test a controller, you need to instantiate one: let controllerUnderTest = new Controller(...). If the Controller has any dependencies (as this is usually the case), these dependencies need to be mocked. For this, use a framework such as sinon. Then you can specify in each test how these mocks should behave. Once you have instantiated the controller, you can execute a method and add assertions. In your case, it looks like you are trying to call the _onTestFunction not on an object, but on the "definition" of the Controller. This does not contain the method, as expected, and results in the error.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda