【问题标题】:mean.js Unexpected request: GET imagesmean.js 意外请求:获取图像
【发布时间】:2014-09-30 14:19:31
【问题描述】:

我是服务器端测试 meanjs 的初学者。简介 我创建了一个服务,它调用执行 HTTP 的工厂。 所以我想了解为什么会出现这个错误:

意外请求:获取图片 $httpBackend (/home/developer/mcd2/public/lib/angular-mocks/angular-mocks.js:1181) 预计不会有更多请求

                            -----MOCK-----
beforeEach(inject(function($controller, $rootScope, _$location_, _$stateParams_, _$httpBackend_,$filter,_Images_) {
            // Set a new global scope
            scope = $rootScope.$new();

            // Point global variables to injected services
            $stateParams = _$stateParams_;
            $httpBackend = _$httpBackend_;
}

it('Test that takes the complete list of all the images in the DB (Images.get)',inject( function (ImagesREST) {
            var Image = new ImagesREST({
                namefile: 'Image_1',
                width: 123,
                height : 321,
                extension : 'JPG',
                tag : 'pippo',
                size:9998,
                type:'img/jpg',
                path:'/asd/add',
                rel:'/asd/Immagine1',
                lastModified:new Date()
            });

            var arrayImages=[Image];

            $httpBackend.expectGET('images').respond(arrayImages);

            var lista = Images.get();

            $httpBackend.flush();

            console.log(lista);
}));

谢谢!

【问题讨论】:

    标签: angularjs meanjs


    【解决方案1】:

    解决方案

    afterEach(function() {
            $httpBackend.verifyNoOutstandingExpectation();
            $httpBackend.verifyNoOutstandingRequest();
        });
    
    it('Test $httpBackend che ritorna la lista delle immagini con get()',inject( function (ImagesREST) {
            var sampleImage = new ImagesREST({
                _id: "542d202ff8e024001a481f70",
                namefile: 'Davide Image',
                width: 235,
                height: 234,
                extension: 'JPG',
                tag: 'dave picture',
                lastMofified: new Date(),
                path: '/home/developer/mcd2/public/modules/uploads/store/images/542d202ff8e024001a481f70/Pippo.jpg',
                rel: 'modules/uploads/store/images/542d202ff8e024001a481f70/Pippo.jpg',
                size:36210,
                type:'image/jpeg'
            });
    
            // Create a sample Images array that includes the new Image
            var sampleImages = [sampleImage];
    
            // Set GET response
            $httpBackend.expectGET('images').respond(sampleImages);
    
            // Run controller functionality
            var ad=Images.get();
            $httpBackend.flush();
    
            expect(ad).toBeDefined();
            expect(ad._id).toEqualData(sampleImages._id);
            expect(ad.namefile).toEqualData(sampleImages.namefile);
            expect(ad.width).toEqualData(sampleImages.width);
            expect(ad.width).toEqualData(sampleImages.width);
            expect(ad.extension).toEqualData(sampleImages.extension);
            expect(ad.tag).toEqualData(sampleImages.tag);
            expect(ad.lastMofified).toEqualData(sampleImages.lastMofified);
            expect(ad.path).toEqualData(sampleImages.path);
            expect(ad.rel).toEqualData(sampleImages.rel);
            expect(ad.size).toEqualData(sampleImages.size);
            expect(ad.type).toEqualData(sampleImages.type);
        }));
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-07
      • 2013-05-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多