Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/backbone.js/2.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
Unit testing 测试模型默认值_Unit Testing_Backbone.js_Jasmine_Marionette - Fatal编程技术网

Unit testing 测试模型默认值

Unit testing 测试模型默认值,unit-testing,backbone.js,jasmine,marionette,Unit Testing,Backbone.js,Jasmine,Marionette,以下模型的所有属性默认值均为null。但是当我用Jasmines toBeNull()函数测试属性时,它的计算结果不是真的。并表示该属性未定义。为什么? 我定义了以下主干模型: Entities.GroupModel = Backbone.Model.extend({ defaults: { "gid" : null, "title" : null, "description" : null, "access_date" :

以下模型的所有属性默认值均为null。但是当我用Jasmines toBeNull()函数测试属性时,它的计算结果不是真的。并表示该属性未定义。为什么?
我定义了以下主干模型:

Entities.GroupModel = Backbone.Model.extend({
    defaults: 
{
    "gid"         : null,
    "title"       : null,
    "description" : null,
    "access_date" : null
}
});
然后在一次测试中,我创建了一个新模型,如下所示

var groupModel = new CCDocUploader.Entities.GroupModel({});

console.log(groupModel);  ///when I inspect the attributes i see they are set to null
console.log(groupModel.gid == null); //this evaluates to true
expect(groupModel.gid).toBeNull(); ///this claims it is undefined and fails...why?

您不能直接访问模块的属性,因为:

groupModel.gid;
您应改为使用:

在您的例子中,您有
groupModel.gid==null
,因为
groupModel.gid
未定义的
,在JS中:

undefined == null // => true
null == null // => true

您不能直接访问模块的属性,因为:

groupModel.gid;
您应改为使用:

在您的例子中,您有
groupModel.gid==null
,因为
groupModel.gid
未定义的
,在JS中:

undefined == null // => true
null == null // => true

您不能直接访问模块的属性,因为:

groupModel.gid;
您应改为使用:

在您的例子中,您有
groupModel.gid==null
,因为
groupModel.gid
未定义的
,在JS中:

undefined == null // => true
null == null // => true

您不能直接访问模块的属性,因为:

groupModel.gid;
您应改为使用:

在您的例子中,您有
groupModel.gid==null
,因为
groupModel.gid
未定义的
,在JS中:

undefined == null // => true
null == null // => true