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

116
Visualizações
BigDecimal library import not defined when Unit test is run

I am trying to test an Effects method in Angular (NGRX) using Jest. The file imports the BigDecimal library. When I run the tests I get Cannot read property 'getPrettyValue' of undefined], undefined would refer to the usage of BigDecimal. I have tried a number of ways to get BigDecimal imported into the file but I still get undefined, even when I import the library into the spec file. The usage of BigDecimal is kept to the service file and only the method I am testing references it. Could it be something wrong with my testbed, or do I need to define the lib in a config file somewhere? Here is my Testbed configuration:

beforeEach(() => {
  TestBed.configureTestingModule({
    imports: [NxModule.forRoot(), HttpClientModule],
    providers: [
      ControllerEffects,
      DataPersistence,
      provideMockActions(() => actions),
      provideMockStore(),
      {
        provide: ControllerService,
        useValue: {
          getResponse: jest.fn()
        }
      }
    ],
    declarations: []
  });
  service = TestBed.inject(ControllerService);
  effects = TestBed.inject(ControllerEffects);
});

And the test that is failing due to this error:

it('should dispatch loadSuccess', () => {
  expect(service).toBeTruthy();
  actions = hot('-a-|', {
    a: ControllerActions.loadAll({ IdFilter: ['id'] })
  });
  const outcome = controllerActions.loadControllerSuccess({
    controller: pos
  });
  const response = cold('-a|', {
    a: {
      data: pos,
      status: { code: 'SUCCESS' }
    }
  });
  const expected = cold('--b|', { b: outcome });
  service.getResponse = jest.fn(() => response);
  expect(effects.loadAll$).toBeObservable(expected);
});

the reference to BigDecimal in the Effects file is returning the formatted value:

import BigDecimal from 'js-big-decimal';


method(input): string {
  return {
    valueString: BigDecimal.getPrettyValue(input.valueString, 3, ',')
  }
}

Any help is greatly appreciated, I've already spent a lot of time on this.

about 4 years ago · Juan Pablo Isaza
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