Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue in ng2-redux-router/lib/esm/index.js #7

Open
vitalii4reva opened this issue Oct 5, 2016 · 2 comments
Open

Issue in ng2-redux-router/lib/esm/index.js #7

vitalii4reva opened this issue Oct 5, 2016 · 2 comments

Comments

@vitalii4reva
Copy link

Hello.

I have an issue while running tests.
npm run test

WARNING in ./~/ng2-redux-router/lib/esm/index.js
Cannot find source file '../../src/index.ts': Error: Can't resolve '../../src/index.ts' in '/node_modules/ng2-redux-router/lib/esm'
 @ ./src/app/app.component.spec.ts 8:27-54
 @ ./src \.spec\.ts
 @ ./config/spec-bundle.js

WARNING in ./~/ng2-redux-router/lib/esm/router.js
Cannot find source file '../../src/router.ts': Error: Can't resolve '../../src/router.ts' in '/node_modules/ng2-redux-router/lib/esm'
 @ ./~/ng2-redux-router/lib/esm/index.js 2:0-41
 @ ./src/app/app.component.spec.ts
 @ ./src \.spec\.ts
 @ ./config/spec-bundle.js

WARNING in ./~/ng2-redux-router/lib/esm/actions.js
Cannot find source file '../../src/actions.ts': Error: Can't resolve '../../src/actions.ts' in '/node_modules/ng2-redux-router/lib/esm'
 @ ./~/ng2-redux-router/lib/esm/index.js 4:0-44
 @ ./src/app/app.component.spec.ts
 @ ./src \.spec\.ts
 @ ./config/spec-bundle.js

WARNING in ./~/ng2-redux-router/lib/esm/reducer.js
Cannot find source file '../../src/reducer.ts': Error: Can't resolve '../../src/reducer.ts' in '/node_modules/ng2-redux-router/lib/esm'
 @ ./~/ng2-redux-router/lib/esm/index.js 3:0-42
 @ ./src/app/app.component.spec.ts
 @ ./src \.spec\.ts
 @ ./config/spec-bundle.js

WARNING in ./~/@angular/core/src/linker/system_js_ng_module_factory_loader.js
45:15 Critical dependency: the request of a dependency is an expression

WARNING in ./~/@angular/core/src/linker/system_js_ng_module_factory_loader.js
57:15 Critical dependency: the request of a dependency is an expression

Can you help me with it ?

@dagstuan
Copy link
Owner

dagstuan commented Oct 5, 2016

Hmm, this seems to be an issue with the esm-code included in the npm package. Do you have any example code that crashes so I can investigate?

@vitalii4reva
Copy link
Author

Sure.

import { TestBed, inject } from '@angular/core/testing';
import { Router, NavigationStart } from '@angular/router';
import {
    NgRedux,
    DevToolsExtension
} from 'ng2-redux';
import { NgReduxRouter } from 'ng2-redux-router';

import { AppComponent } from './app.component';
import { UserSessionActions } from './store/actions/user-session.actions';
import { RouterActions } from './store/actions/router.actions';
import { MiddlewaresProvider } from './store';
import { LoginService } from './shared/services/login.service';
import { LOGIN_ROUTE } from './app.routes';

class UserSessionActionsMock {
    public restoreToken = jasmine.createSpy('restoreToken');
};

let reduxMapSpy;
class NgReduxMock {
    public select = jasmine.createSpy('select').and.callFake((param: string): any => {
        if (param === 'sidebar') {
            return {
                map(cb) {
                    reduxMapSpy();
                    cb({ isVisible: true });
                }
            };
        }
        return {
            subscribe(cb) {
                cb('route');
            }
        };
    });
    public configureStore = jasmine.createSpy('configureStore');
    public dispatch = jasmine.createSpy('dispatch');
}

class DevToolsExtensionMock {
    public isEnabled = jasmine.createSpy('isEnabled').and.callFake(() => {
        return true;
    });
    public enhancer = jasmine.createSpy('enhancer');
}

class MiddlewaresProviderMock {
    public getMiddlewares = jasmine.createSpy('getMiddlewares');
}

class NgReduxRouterMock {
    public dispatch = jasmine.createSpy('dispatch');
    public initialize = jasmine.createSpy('initialize');
}

class RouterActionsMock {
    public updateLocation = jasmine.createSpy('updateLocation');
}

class RouterMock {
    public navigate = jasmine.createSpy('navigate');
    public events = {
        filter(eventFilterCb) {
            eventFilterCb(new NavigationStart(1, '/login'));
            return {
                flatMap(flatMapCb) {
                    return {
                        subscribe(subscribeCb) {
                            subscribeCb(flatMapCb());
                        }
                    };
                }
            };
        }
    };
};

let isLoggedIn = false;
class LoginServiceMock {
    public get isLoggedIn() {
        return isLoggedIn;
    }
}

describe('AppComponent', () => {
    let userSessionActionsMock: UserSessionActionsMock;
    let ngReduxMock: NgReduxMock;
    let ngReduxRouterMock: NgReduxRouterMock;
    let routerMock: RouterMock;
    let devToolsExtensionMock: DevToolsExtensionMock;
    let middlewaresProviderMock: MiddlewaresProviderMock;
    let routerActionsMock: RouterActionsMock;
    let loginServiceMock: LoginServiceMock;
    // Set up providers
    beforeEach(() => {
        userSessionActionsMock = new UserSessionActionsMock();
        ngReduxMock = new NgReduxMock();
        ngReduxRouterMock = new NgReduxRouterMock();
        routerMock = new RouterMock();
        devToolsExtensionMock = new DevToolsExtensionMock();
        middlewaresProviderMock = new MiddlewaresProviderMock();
        routerActionsMock = new RouterActionsMock();
        loginServiceMock = new LoginServiceMock();

        reduxMapSpy = jasmine.createSpy('reduxMapSpy');

        TestBed.configureTestingModule({
            providers: [
                AppComponent,
                { provide: UserSessionActions, useValue: userSessionActionsMock },
                { provide: NgRedux, useValue: ngReduxMock },
                { provide: NgReduxRouter, useValue: ngReduxRouterMock },
                { provide: Router, useValue: routerMock },
                { provide: DevToolsExtension, useValue: devToolsExtensionMock },
                { provide: MiddlewaresProvider, useValue: middlewaresProviderMock },
                { provide: RouterActions, useValue: routerActionsMock },
                { provide: LoginService, useValue: loginServiceMock },
            ]
        });
    });

    // Tests

    it('check if userSession and loader properties have been set',
        inject([AppComponent], appComponent => {
            expect(ngReduxMock.select).toHaveBeenCalledWith('sidebar');
            expect(reduxMapSpy).toHaveBeenCalled();
            expect(ngReduxMock.select).toHaveBeenCalledWith('loader');
            expect(ngReduxMock.configureStore).toHaveBeenCalled();
            expect(middlewaresProviderMock.getMiddlewares).toHaveBeenCalled();
            expect(devToolsExtensionMock.isEnabled).toHaveBeenCalled();
            expect(devToolsExtensionMock.enhancer).toHaveBeenCalled();
            expect(ngReduxRouterMock.initialize).toHaveBeenCalled();
            expect(ngReduxMock.select).toHaveBeenCalledWith('router');
            expect(routerMock.navigate).toHaveBeenCalledWith(['route']);
            expect(userSessionActionsMock.restoreToken).toHaveBeenCalled();
        })
    );

    it('test "ngOnInit" function for case when isLoggedIn is true',
        inject([AppComponent], appComponent => {
            isLoggedIn = true;
            appComponent.ngOnInit();
            expect(routerActionsMock.updateLocation).not.toHaveBeenCalled();
        })
    );

    it('test "ngOnInit" function for case when isLoggedIn is false',
        inject([AppComponent], appComponent => {
            isLoggedIn = false;
            appComponent.ngOnInit();
            expect(routerActionsMock.updateLocation).toHaveBeenCalledWith(LOGIN_ROUTE);
        })
    );
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants