title: Karma Jasmin- Why my test cases are failing randomly even if there are no test cases?
body: <p>Here is my oninit class, which I am not supposed to change.</p>
  <pre><code>  ngOnInit(): void {
          this.setCustomizedValues();
          this.sub = PubSub.subscribe('highlightEntity', (subId, entityIdentifier: string) =&gt; {
            document.querySelector(entityIdentifier).classList.add('highlight');
      
            setTimeout(() =&gt; {
              document.querySelector(entityIdentifier).classList.remove('highlight');
            }, 2000);
      
          });
        }
  </code></pre>
  <p>and here is minimal test setup</p>
  <pre><code>describe('aComponent', () =&gt; {
  
      
    let httpCallerServiceStub = jasmine.createSpyObj('httpCallerServiceStub', ['get']);
  
    let fixture: ComponentFixture&lt;aComponent&gt;;
    let componentInstance: aComponent;
    localStorage.clear();
    beforeEach(() =&gt; {
      TestBed.configureTestingModule({
        declarations: [aComponent],
        providers: [
          {
            provide: HttpCallerService,
            useValue: httpCallerServiceStub
          }],
        imports: [CommonModule, CmcSpinnerModule, NgbModule],
      }).compileComponents();
  
      fixture = TestBed.createComponent(aComponent);
      componentInstance = fixture.componentRef.instance;
      fixture.autoDetectChanges();
    });
  
   describe('ngOnInit method', () =&gt; {
      beforeEach(() =&gt; {
        fixture.componentInstance.customized = {};
      });
  
      it('should initialize with minimum input', () =&gt; {
        // Triggers ngOnInit
        fixture.detectChanges();
        expect(fixture.componentInstance.customized).toEqual({});
      });
    });
  </code></pre>
  <p>The issue is the tests are failing randomly with the error that classlist not found of null</p>
  <pre><code>&quot;message&quot;: &quot;An error was thrown in afterAll\nTypeError: Cannot read property 'classList' of null\n    at &lt;Jasmine&gt;\n 
     at webpack:///components/path/aComponent.ts:35:53
  </code></pre>
  <p>this line no 35 refers to this lines in oninit function</p>
  <pre><code>   setTimeout(() =&gt; {
                  document.querySelector(entityIdentifier).classList.remove('highlight');
                }, 2000);
  </code></pre>
  <p>So few questions here</p>
  <ol>
  <li><p>I have tried putting tick(2000) and fake asysnc in a simple test of ngonit but still it is giving me the same random errors (as suggested by <a href="https://stackoverflow.com/questions/64242278/how-to-write-test-cases-for-subscriber-and-timeout-inside-ngonit-method/64242699?noredirect=1#comment113605224_64242699">this answer</a> )</p>
  </li>
  <li><p>Is my testbed configuration is missing something? because even when I comment out the oninit test and just check some random function even without fixture.detectChanges(), the same random error is happening.</p>
  </li>
  <li><p>if I run tests using fdescibe, all the tests get passed every time. This issue only happens when I removed f from fdescribe and run all the tests of other components as well.</p>
  </li>
  </ol>
  <p>Please guide me, I am stuck here since last 4 days.</p>