简体   繁体   中英

Aurelia. Testing. TypeError: config.addPipelineStep is not a function

I use default Aurelia's sceleton-esnext updated to last version . I added this line to App ( Example from doc. Customizing the Navigation Pipeline )

config.addPipelineStep('authorize', AuthorizeStep);

After this I catch error running 'gulp test'

Chrome 52.0.2743 (Linux 0.0.0) the App module contains a router property FAILED
TypeError: config.addPipelineStep is not a function

Test

  it('contains a router property', () => {
    expect(sut.router).toBeDefined();
  });

Test is going well without line.

I just came across this issue. To fix, you just need to add an empty method into your RouterStub:

class RouterStub {
    configure(handler) {
        handler(this);
    }

    map(routes) {
        this.routes = routes;
    }

    addPipelineStep(stepName, stepClass) {
    }
}

then in your test:

describe('the App module', () => {
    var app;
    var mockedRouter;

    beforeEach(() => {
        mockedRouter = new RouterStub();
        app = new App();
        app.configureRouter(mockedRouter, mockedRouter);
    });

    it('contains a router property', () => {
        expect(app.router).toBeDefined();
    });
});

If you're trying to test the pipeline step you'll need to mock the router itself and test the actual logic, but if you just want your tests to run (ie be defined, check the router title etc), this will work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM