mercredi 4 janvier 2017

How to test Angular service that post with form data?

Test

describe('Transport Cost attachment API service', function () {
    var service;
    var $httpBackend;

    beforeEach(module('app'));

    beforeEach(inject(function (_$httpBackend_, TransportCostService) {
        $httpBackend = _$httpBackend_;
        service = TransportCostService;
    }));

    it('create(): should create a transport cost attachment', function (done) {
        var transportCost = {expenseId: 123};
        var data = 'form data';
        var headers = {'Content-Type': 'multipart/form-data'};
        $httpBackend.expectPOST('/api/expense-claim/123/transport-cost-attachment/', transportCost, data, {headers: headers}).respond(201, transportCost);

        service.create(transportCost, data, {headers: headers}).then(function () {
            done();
        });
        $httpBackend.flush();
    });
});

Error

PhantomJS 2.1.1 (Linux 0.0.0) Transport Cost attachment API service create(): should create a transport cost attachment FAILED
        SyntaxError: JSON Parse error: Unexpected identifier "form" in node_modules/angular/angular.js (line 1345)
        parse@[native code]
        fromJson@node_modules/angular/angular.js:1345:19
        matchData@node_modules/angular-mocks/angular-mocks.js:1940:85
        $httpBackend@node_modules/angular-mocks/angular-mocks.js:1385:33
        sendReq@node_modules/angular/angular.js:12023:21
        serverRequest@node_modules/angular/angular.js:11818:23
        processQueue@node_modules/angular/angular.js:16692:30
        node_modules/angular/angular.js:16708:39
        $eval@node_modules/angular/angular.js:17990:28
        $digest@node_modules/angular/angular.js:17804:36
        flush@node_modules/angular-mocks/angular-mocks.js:1806:45
        test/transport-cost-attachment.service.tests.js:23:21
        test/tax.service.tests.js:60:8
        processQueue@node_modules/angular/angular.js:16692:30
        node_modules/angular/angular.js:16708:39
        $eval@node_modules/angular/angular.js:17990:28
        $digest@node_modules/angular/angular.js:17804:36
        $apply@node_modules/angular/angular.js:18098:31
        done@node_modules/angular/angular.js:12078:53
        handleResponse@node_modules/angular-mocks/angular-mocks.js:1369:17
        flush@node_modules/angular-mocks/angular-mocks.js:1819:37
        test/tax.service.tests.js:62:21
        test/tax.service.tests.js:49:8
        processQueue@node_modules/angular/angular.js:16692:30
        node_modules/angular/angular.js:16708:39
        $eval@node_modules/angular/angular.js:17990:28
        $digest@node_modules/angular/angular.js:17804:36
        $apply@node_modules/angular/angular.js:18098:31
        done@node_modules/angular/angular.js:12078:53
        handleResponse@node_modules/angular-mocks/angular-mocks.js:1369:17
        flush@node_modules/angular-mocks/angular-mocks.js:1819:37
        test/tax.service.tests.js:52:21
        test/tax.service.tests.js:39:8
        processQueue@node_modules/angular/angular.js:16692:30
        node_modules/angular/angular.js:16708:39
        $eval@node_modules/angular/angular.js:17990:28
        $digest@node_modules/angular/angular.js:17804:36
        $apply@node_modules/angular/angular.js:18098:31
        done@node_modules/angular/angular.js:12078:53
        handleResponse@node_modules/angular-mocks/angular-mocks.js:1369:17
        flush@node_modules/angular-mocks/angular-mocks.js:1819:37
        test/tax.service.tests.js:41:21
        test/tax.service.tests.js:29:8
        processQueue@node_modules/angular/angular.js:16692:30
        node_modules/angular/angular.js:16708:39
        $eval@node_modules/angular/angular.js:17990:28
        $digest@node_modules/angular/angular.js:17804:36
        $apply@node_modules/angular/angular.js:18098:31
        done@node_modules/angular/angular.js:12078:53
        handleResponse@node_modules/angular-mocks/angular-mocks.js:1369:17
        flush@node_modules/angular-mocks/angular-mocks.js:1819:37
        test/tax.service.tests.js:31:21
        test/tax.service.tests.js:19:8
        processQueue@node_modules/angular/angular.js:16692:30
        node_modules/angular/angular.js:16708:39
        $eval@node_modules/angular/angular.js:17990:28
        $digest@node_modules/angular/angular.js:17804:36
        $apply@node_modules/angular/angular.js:18098:31
        done@node_modules/angular/angular.js:12078:53
        handleResponse@node_modules/angular-mocks/angular-mocks.js:1369:17
        flush@node_modules/angular-mocks/angular-mocks.js:1819:37
        test/tax.service.tests.js:21:21
        test/receipt.service.tests.js:60:8
        processQueue@node_modules/angular/angular.js:16692:30
        node_modules/angular/angular.js:16708:39
        $eval@node_modules/angular/angular.js:17990:28
        $digest@node_modules/angular/angular.js:17804:36
        $apply@node_modules/angular/angular.js:18098:31
        done@node_modules/angular/angular.js:12078:53
        handleResponse@node_modules/angular-mocks/angular-mocks.js:1369:17
        flush@node_modules/angular-mocks/angular-mocks.js:1819:37
        test/receipt.service.tests.js:62:21
        test/receipt.service.tests.js:49:8
        processQueue@node_modules/angular/angular.js:16692:30
        node_modules/angular/angular.js:16708:39
        $eval@node_modules/angular/angular.js:17990:28
        $digest@node_modules/angular/angular.js:17804:36
        $apply@node_modules/angular/angular.js:18098:31
        done@node_modules/angular/angular.js:12078:53
        handleResponse@node_modules/angular-mocks/angular-mocks.js:1369:17
        flush@node_modules/angular-mocks/angular-mocks.js:1819:37
        test/receipt.service.tests.js:52:21
        test/receipt.service.tests.js:39:8
        processQueue@node_modules/angular/angular.js:16692:30
        node_modules/angular/angular.js:16708:39
        $eval@node_modules/angular/angular.js:17990:28
        $digest@node_modules/angular/angular.js:17804:36
        $apply@node_modules/angular/angular.js:18098:31
        done@node_modules/angular/angular.js:12078:53
        handleResponse@node_modules/angular-mocks/angular-mocks.js:1369:17
        flush@node_modules/angular-mocks/angular-mocks.js:1819:37
        test/receipt.service.tests.js:41:21
        test/receipt.service.tests.js:29:8
        processQueue@node_modules/angular/angular.js:16692:30
        node_modules/angular/angular.js:16708:39
        $eval@node_modules/angular/angular.js:17990:28
        $digest@node_modules/angular/angular.js:17804:36
        $apply@node_modules/angular/angular.js:18098:31
        done@node_modules/angular/angular.js:12078:53
        handleResponse@node_modules/angular-mocks/angular-mocks.js:1369:17
        flush@node_modules/angular-mocks/angular-mocks.js:1819:37
        test/receipt.service.tests.js:31:21
        test/receipt.service.tests.js:19:8
        processQueue@node_modules/angular/angular.js:16692:30
        node_modules/angular/angular.js:16708:39
        $eval@node_modules/angular/angular.js:17990:28
        $digest@node_modules/angular/angular.js:17804:36
        $apply@node_modules/angular/angular.js:18098:31
        done@node_modules/angular/angular.js:12078:53
        handleResponse@node_modules/angular-mocks/angular-mocks.js:1369:17
        flush@node_modules/angular-mocks/angular-mocks.js:1819:37
        test/receipt.service.tests.js:21:21
        Error: Unsatisfied requests: POST /api/expense-claim/123/transport-cost-attachment/ in node_modules/angular-mocks/angular-mocks.js (line 1843)
        verifyNoOutstandingExpectation@node_modules/angular-mocks/angular-mocks.js:1843:74
        test/transport-cost-attachment.service.tests.js:58:46
        test/tax.service.tests.js:60:8
        processQueue@node_modules/angular/angular.js:16692:30
        node_modules/angular/angular.js:16708:39
        $eval@node_modules/angular/angular.js:17990:28
        $digest@node_modules/angular/angular.js:17804:36
        $apply@node_modules/angular/angular.js:18098:31
        done@node_modules/angular/angular.js:12078:53
        handleResponse@node_modules/angular-mocks/angular-mocks.js:1369:17
        flush@node_modules/angular-mocks/angular-mocks.js:1819:37
        test/tax.service.tests.js:62:21
        test/tax.service.tests.js:49:8
        processQueue@node_modules/angular/angular.js:16692:30
        node_modules/angular/angular.js:16708:39
        $eval@node_modules/angular/angular.js:17990:28
        $digest@node_modules/angular/angular.js:17804:36
        $apply@node_modules/angular/angular.js:18098:31
        done@node_modules/angular/angular.js:12078:53
        handleResponse@node_modules/angular-mocks/angular-mocks.js:1369:17
        flush@node_modules/angular-mocks/angular-mocks.js:1819:37
        test/tax.service.tests.js:52:21
        test/tax.service.tests.js:39:8
        processQueue@node_modules/angular/angular.js:16692:30
        node_modules/angular/angular.js:16708:39
        $eval@node_modules/angular/angular.js:17990:28
        $digest@node_modules/angular/angular.js:17804:36
        $apply@node_modules/angular/angular.js:18098:31
        done@node_modules/angular/angular.js:12078:53
        handleResponse@node_modules/angular-mocks/angular-mocks.js:1369:17
        flush@node_modules/angular-mocks/angular-mocks.js:1819:37
        test/tax.service.tests.js:41:21
        test/tax.service.tests.js:29:8
        processQueue@node_modules/angular/angular.js:16692:30
        node_modules/angular/angular.js:16708:39
        $eval@node_modules/angular/angular.js:17990:28
        $digest@node_modules/angular/angular.js:17804:36
        $apply@node_modules/angular/angular.js:18098:31
        done@node_modules/angular/angular.js:12078:53
        handleResponse@node_modules/angular-mocks/angular-mocks.js:1369:17
        flush@node_modules/angular-mocks/angular-mocks.js:1819:37
        test/tax.service.tests.js:31:21
        test/tax.service.tests.js:19:8
        processQueue@node_modules/angular/angular.js:16692:30
        node_modules/angular/angular.js:16708:39
        $eval@node_modules/angular/angular.js:17990:28
        $digest@node_modules/angular/angular.js:17804:36
        $apply@node_modules/angular/angular.js:18098:31
        done@node_modules/angular/angular.js:12078:53
        handleResponse@node_modules/angular-mocks/angular-mocks.js:1369:17
        flush@node_modules/angular-mocks/angular-mocks.js:1819:37
        test/tax.service.tests.js:21:21
        test/receipt.service.tests.js:60:8
        processQueue@node_modules/angular/angular.js:16692:30
        node_modules/angular/angular.js:16708:39
        $eval@node_modules/angular/angular.js:17990:28
        $digest@node_modules/angular/angular.js:17804:36
        $apply@node_modules/angular/angular.js:18098:31
        done@node_modules/angular/angular.js:12078:53
        handleResponse@node_modules/angular-mocks/angular-mocks.js:1369:17
        flush@node_modules/angular-mocks/angular-mocks.js:1819:37
        test/receipt.service.tests.js:62:21
        test/receipt.service.tests.js:49:8
        processQueue@node_modules/angular/angular.js:16692:30
        node_modules/angular/angular.js:16708:39
        $eval@node_modules/angular/angular.js:17990:28
        $digest@node_modules/angular/angular.js:17804:36
        $apply@node_modules/angular/angular.js:18098:31
        done@node_modules/angular/angular.js:12078:53
        handleResponse@node_modules/angular-mocks/angular-mocks.js:1369:17
        flush@node_modules/angular-mocks/angular-mocks.js:1819:37
        test/receipt.service.tests.js:52:21
        test/receipt.service.tests.js:39:8
        processQueue@node_modules/angular/angular.js:16692:30
        node_modules/angular/angular.js:16708:39
        $eval@node_modules/angular/angular.js:17990:28
        $digest@node_modules/angular/angular.js:17804:36
        $apply@node_modules/angular/angular.js:18098:31
        done@node_modules/angular/angular.js:12078:53
        handleResponse@node_modules/angular-mocks/angular-mocks.js:1369:17
        flush@node_modules/angular-mocks/angular-mocks.js:1819:37
        test/receipt.service.tests.js:41:21
        test/receipt.service.tests.js:29:8
        processQueue@node_modules/angular/angular.js:16692:30
        node_modules/angular/angular.js:16708:39
        $eval@node_modules/angular/angular.js:17990:28
        $digest@node_modules/angular/angular.js:17804:36
        $apply@node_modules/angular/angular.js:18098:31
        done@node_modules/angular/angular.js:12078:53
        handleResponse@node_modules/angular-mocks/angular-mocks.js:1369:17
        flush@node_modules/angular-mocks/angular-mocks.js:1819:37
        test/receipt.service.tests.js:31:21
        test/receipt.service.tests.js:19:8
        processQueue@node_modules/angular/angular.js:16692:30
        node_modules/angular/angular.js:16708:39
        $eval@node_modules/angular/angular.js:17990:28
        $digest@node_modules/angular/angular.js:17804:36
        $apply@node_modules/angular/angular.js:18098:31
        done@node_modules/angular/angular.js:12078:53
        handleResponse@node_modules/angular-mocks/angular-mocks.js:1369:17
        flush@node_modules/angular-mocks/angular-mocks.js:1819:37
        test/receipt.service.tests.js:21:21
PhantomJS 2.1.1 (Linux 0.0.0): Executed 168 of 170 (1 FAILED) (skipped 2) (1.107 secs / 1.213 secs)
error Command failed with exit code 1.

Aucun commentaire:

Enregistrer un commentaire