Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 未定义:value.push(新资源(项目)_Javascript_Angularjs_Unit Testing_Karma Jasmine - Fatal编程技术网

Javascript 未定义:value.push(新资源(项目)

Javascript 未定义:value.push(新资源(项目),javascript,angularjs,unit-testing,karma-jasmine,Javascript,Angularjs,Unit Testing,Karma Jasmine,我试图测试一个工厂,但我遇到了一个奇怪的错误。我环顾四周,但没有发现类似的问题。你知道我做错了什么吗 TypeError:“undefined”不是函数(计算“value.push(新资源(项目))) 使用angluarjsv1.3.20 factory.js test.js describe('My Service', function () { // Then we can start by loading the main application module befo

我试图测试一个工厂,但我遇到了一个奇怪的错误。我环顾四周,但没有发现类似的问题。你知道我做错了什么吗

TypeError:“undefined”不是函数(计算“value.push(新资源(项目)))

使用angluarjs
v1.3.20

factory.js

test.js

describe('My Service', function () {


    // Then we can start by loading the main application module
    beforeEach(module(ApplicationConfiguration.applicationModuleName));

    afterEach(inject(function($httpBackend){
        //These two calls will make sure that at the end of the test, all expected http calls were made
        $httpBackend.verifyNoOutstandingExpectation();
        $httpBackend.verifyNoOutstandingRequest();
    }));

    it('mock http call', inject(function($httpBackend, Business) {
        var resource = new Business({
            _id:'abcd'
        });
        var arraya = [{
            _id:'abcd'
        }, {
            _id:'abcde'
        }];
        //Create an expectation for the correct url, and respond with a mock object
        $httpBackend.expectGET('api/businesses/abcd').respond(200, arraya)

        resource.$query();

        //Because we're mocking an async action, ngMock provides a method for us to explicitly flush the request
        $httpBackend.flush();

        //Now the resource should behave as expected
        console.log(resource);
        //expect(resource.name).toBe('test');
    }));

});

XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

你不应该只在脸红后才期待吗

resource.$query();

//Because we're mocking an async action, ngMock provides a method for us to explicitly flush the request
$httpBackend.flush();

//Create an expectation for the correct url, and respond with a mock object
$httpBackend.expectGET('api/businesses/abcd').respond(200, arraya);

这可能很愚蠢,但你不应该把
expectGET
放在
flush()
之后吗?不。当我更改顺序时,我得到
错误:意外请求:获取api/business/abcd
嗯..我告诉过你,这可能很愚蠢:P对不起,我帮不上忙谢谢你的努力。我要更新angular&看看这是否奏效。
resource.$query();

//Because we're mocking an async action, ngMock provides a method for us to explicitly flush the request
$httpBackend.flush();

//Create an expectation for the correct url, and respond with a mock object
$httpBackend.expectGET('api/businesses/abcd').respond(200, arraya);