Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/22.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
Angularjs 理解角度';s'inject'带有测试_Angularjs - Fatal编程技术网

Angularjs 理解角度';s'inject'带有测试

Angularjs 理解角度';s'inject'带有测试,angularjs,Angularjs,查看以下示例: 然后,模块的测试: describe('notifications archive tests', function () { var notificationsArchive; beforeEach(module('archive')); beforeEach(inject(function (_notificationsArchive_) { notificationsArchive = _notificationsArchive_;

查看以下示例:

然后,模块的测试:

describe('notifications archive tests', function () {
   var notificationsArchive;

   beforeEach(module('archive'));

   beforeEach(inject(function (_notificationsArchive_) {
        notificationsArchive = _notificationsArchive_;
   }));

   it('should give access to the archived items', function () {
       var notification = {msg: 'Old message.'};

    notificationsArchive.archive(notification);

    expect(notificationsArchive.getArchived())
          .toContain(notification);
    });
});
在每次(注入…之前的第二次
中发生了什么

beforeEach(inject(function (_notificationsArchive_) {
    notificationsArchive = _notificationsArchive_;
}));
这只是说,在每次测试之前,获取notificationsArchive的一个实例。然后它将该实例分配给一个可以在实际测试用例中使用的变量。notificationsArchive周围的下划线只是语法糖,因此您不必为测试用户使用的变量想出另一个名称


这只是说在每次测试之前,获取notificationsArchive的一个实例。然后它将该实例分配给一个可以在实际测试用例中使用的变量。notificationsArchive周围的下划线只是语法上的糖分,所以您不必为您的测试用户使用的变量想出另一个名称。

它正在注入notificationsArchive服务进入一个函数,该函数在每次测试之前将该服务分配给局部变量“notificationsArchive”。名称中的下划线将被忽略


它将notificationsArchive服务注入到函数中,该函数在每次测试之前将该服务分配给局部变量“notificationsArchive”。名称中的下划线将被忽略

beforeEach(inject(function (_notificationsArchive_) {
    notificationsArchive = _notificationsArchive_;
}));