akserg / ng2-slim-loading-bar

Angular 2 component shows slim loading bar at the top of the page.
MIT License
358 stars 93 forks source link

Version 2.0.5 #32

Closed benjaminbhm closed 7 years ago

benjaminbhm commented 7 years ago

I'm submitting a ... (check one with "x")

[X] bug report => check the FAQ and search github for a similar issue or PR before submitting
[ ] support request => check the FAQ and search github for a similar issue before submitting
[ ] feature request

Current behavior It makes some Tests fail for unknown Reason, here are some outputs of failing tests:

create
      ✖ submits data in correct form
        PhantomJS 2.1.1 (Mac OS X 0.0.0)
      Error: No provider for EventEmitter! (line 2906)

      ✖ can create new message with valid data
        PhantomJS 2.1.1 (Mac OS X 0.0.0)
      Error: No provider for EventEmitter! (line 2906)

      ✖ returns error for invalid data
        PhantomJS 2.1.1 (Mac OS X 0.0.0)
      Error: No provider for EventEmitter! (line 2906)

Expected/desired behavior Those Test should not fail. It worked perfectly fine with the version 2.0.4, which we are currently using for a temporary fix

Reproduction of the problem If the current behavior is a bug or you can illustrate your feature request better with an example, please provide the steps to reproduce and if possible a minimal demo of the problem via https://plnkr.co or similar.

As we do not know the reason for the failing tests, I will just copy paste some tests into here.

Example Test:

  describe('create', () => {
    it('submits data in correct form', () => {
      HttpMockHelpers.mockResponseSuccess(mockBackend, MockMessageService.getMockDataOne(0));
      mockBackend.connections.subscribe((connection: MockConnection) => {
        expect(connection.request.method).toBe(RequestMethod.Post);
        expect(_.isArray(JSON.parse(connection.request.getBody()).data)).toBeFalsy();
      });
      service.create(testMessages[0]);
    });

    it('can create new message with valid data', () => {
      HttpMockHelpers.mockResponseSuccess(mockBackend, MockMessageService.getMockDataOne(0));
      let response;
      service.create(testMessages[0]).subscribe(f => response = f);
      expect(response).toEqualData(testMessages[0]);
    });

    it('returns error for invalid data', () => {
      let message = new Message({
        subject: 'Message name'
      });
      let errorMsg = 'Required messages are missing';
      let response;
      HttpMockHelpers.mockResponseError(mockBackend, errorMsg);
      service.create(message).subscribe(null, err => response = err.body);
      expect(response).toEqualData(errorMsg);
    });
  });

What is the expected behavior? All tests should run fine

What is the motivation / use case for changing the behavior?

Please tell us about your environment: Mac OS X Sierra 10.12.2 Angular 2 Project, Jasmine with Karma Plugin as Testing framework

akserg commented 7 years ago

Hi @benjaminbhm, Can you, please copy the full test file because I can't see the initialisation of your tests.

Kjir commented 7 years ago

Here is an example test that will fail with version 2.0.5 and 2.0.7 (I assume 2.0.6 as well), but will work correctly with version 2.0.4:

import { inject, TestBed } from '@angular/core/testing';
// Load the implementations that should be tested
import { AppComponent } from './app.component';
import { Router, Event, NavigationStart, NavigationEnd, NavigationCancel, NavigationError } from '@angular/router';
import { AppSettings } from './app.settings';
import { MockRouter } from './mocks';
import { MockVHTranslateLoader } from './utils/translate-loader.mock';
import { ViewContainerRef } from '@angular/core';
import { SlimLoadingBarService } from 'ng2-slim-loading-bar';

describe('App', () => {
  // provide our implementations or mocks to the dependency injector
  beforeEach(() => TestBed.configureTestingModule({
    imports: [
      MockVHTranslateLoader.getImports()
    ],
    providers: [AppComponent,
                ViewContainerRef,
                { provide: Router, useClass: MockRouter },
                SlimLoadingBarService]
  }));

  it('can instantiate app component', inject([AppComponent], (app: AppComponent) => {
    expect(app).toBeDefined();
  }));
});
akserg commented 7 years ago

Fixed in 2.4.0