0

While writing unit tests for an Angular project using Karma and Jasmine, I met a weird issue. When I test only a component using fdescribe it says SUCCESS. But if I replace 'fdescribe' with 'describe' and check all tests work fine, then it throws an error for the above component.

The said component uses Google Maps feature, so I added a mock to karma.config.js like this.

module.exports = function(config) {
  config.set({
    basePath: '',
    // ... other settings

    files: ['src/testing/google-map-mock.js'],   <-- added this for google maps
    // goes next settings
  });
};

After added the mockup, it worked with fdescribe, but still doesn't work with describe. So weird. Does anyone have any idea? I think the problem comes from between karma config and jasmine, with fdescribe', the mock file is injected exactly, but with describe` it's not. I think this is the problem. Please help me if anyone have any idea for me.

Thank you!

I added a mock to solve google is not defined error. After adding the mock, the component test works with fdescribe, but doesn't work with describe clause.

iconique
  • 1,115
  • 13
  • 16
  • Please post code. –  Feb 16 '23 at 20:05
  • Very likely you have some form of state persisting between your individual tests. When you run with `fdescribe`, no other test touches the shared state (maybe your google map mock?). When you run with `describe`, some other test alters that shared state, which causes your specific test to fail. – wlf Feb 18 '23 at 09:19
  • [wlf](https://stackoverflow.com/users/1188074/wlf), that makes sense, I will check if there's another google maps mock for other tests. – iconique Feb 20 '23 at 14:24

0 Answers0