如何验证返回404的Pact测试

时间:2018-10-03 07:36:34

标签: angularjs typescript pact

我在Angular / Typescript项目中有以下互动

export const getInvalidStuff: InteractionObject = {
    state: 'stuff data exists',
    uponReceiving: 'a request for stuff using an invalid level',
    withRequest: {
        headers: {
            'Content-Type': 'application/json',
            'Accept': 'application/json'
        },
        method: 'GET',
        path: '/api/levels/foo/stuff',
    },
    willRespondWith: {
        status: 404
    }
};

并按以下方式运行Pact测试,其中提供程序的类型为PactWeb

it('should return 404 when requesting data that does not exist', (done) => {
    provider.addInteraction(interactions.getInvalidStuff).then(() => {

        var $injector = angular.injector(['ng']);
        let $rootScope = $injector.get('$rootScope');
        const service = setupStuffService($injector, config);
        service.getStuff('foo').then((result) => {
            provider.verify().then(done, e => done.fail(e));
        }, e => { console.log(e); done.fail(e); })


        $rootScope.$apply();
    }), error => done.fail(error);        
});

但是pact测试失败并显示“ Failed:[object Object]”,但没有帮助。我的200状态代码契约全部正常。只是在努力使错误处理程序启动并运行。

有什么想法吗?

0 个答案:

没有答案