- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我的 Sequelize 模型中有以下类方法:
getById(id) {
return new Promise((resolve, reject) => {
var Conference = sequelize.models.conference;
Conference.findById(id).then(function(conference) {
if (_.isObject(conference)) {
resolve(conference);
} else {
throw new ResourceNotFound(conference.name, {id: id});
}
}).catch(function(err) {
reject(err);
});
});
}
现在我想用 chai 测试我的方法。但现在当我执行 Conference.getById(confereceId)
时,我得到以下信息:
Promise {
_bitField: 0,
_fulfillmentHandler0: undefined,
_rejectionHandler0: undefined,
_promise0: undefined,
_receiver0: undefined }
这是正确的吗?我如何用 chai 断言它的结果?
最佳答案
您的 Conference.getById(confereceId)
调用返回一个 Promise,因此您应该首先通过 then
解析 Promise,并使用 chai
断言其结果,如下所示:
const assert = require('chai').assert;
Conference
.getById(confereceId)
.then(conf => {
assert.isObject(conf);
// ...other assertions
}, err => {
assert.isOk(false, 'conference not found!');
// no conference found, fail assertion when it should be there
});
关于node.js - getById() 返回未定义的 Promise,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43607902/
我正在使用 Entity Framework 并希望在 Repository 类中创建通用的 GetById 方法并进行预加载: 这是我使用延迟加载的方法: public virtual TEntit
因此,我使用带有 asp.net core 和 Entity Framework 6 的存储库模式从服务层访问数据库。问题是我有一个具有复合键的实体,而通用存储库采用 int 作为参数,因此我无法将多
我没有像 here 那样在数据存储读取上获得强一致性. 代码(使用Objectify)。 a = getById() // ofy().load().type(this.clazz).id(id).n
请参阅以下文章:https://www.codeproject.com/Articles/555855/Introduction-to-CQRS和 http://enterprisecraftsman
我的理解是您必须编写隔离功能的单元测试。因此,给定一个具有此方法的存储库类: Entity GetById(Guid id) 和一个假实现(使用字典进行存储),如果不先添加实体,您将如何编写测试?可以
我正在寻找一种创建通用 GetById 的方法,它将 params object[] 作为参数,知道找到键/s 字段并知道找到相关实体。 在寻找解决方案的过程中,我想到了一个返回 PK 字段定义的泛型
其次,我使用 raphaeljs 库在不同路径中进行了 SVG 形式转换。 我想通过raphaeljs 2.1.0 => getById(id); 的功能调用他来获取路径但是 Chrome 或 Fir
我将检查是否存在具有特定 id(我将其命名为“setid”)的元素。如果没有创建它并设置 id。不幸的是这不起作用。错误在哪里? 提前致谢。亚历克斯 var resultSet; var setId
这个问题已经有答案了: "document.getElementByClass is not a function" (12 个回答) 已关闭 7 年前。 我一直在使用以下代码来替换页面上 id 内的
我的 Sequelize 模型中有以下类方法: getById(id) { return new Promise((resolve, reject) => { var
我正在尝试使用 mgo (mongodb) 创建一个简单的 CRUD。 这是我的代码: package main import ( "fmt" "time" "gopkg.in
我有一个通用存储库,我正在尝试为我的单元测试创建最小起订量实现。我需要创建一个 GetById 方法。这是我决定将其转换为使用泛型之前的最小起订量实现。 mockUserRepository.Se
因此,如果用户使用屏幕足够大的设备(例如三星 Galaxy Tab),我会看到 2 个 fragment 。。 现在我正在显示 fragment 列表两次(同一 fragment 两次)。在 frag
public abstract class GenericRepository : IDisposable, IGenericRepository where T : class { prot
我正在尝试为我目前正在处理的基于 Entity Framework 的项目编写一个通用的通用存储库模式模板类。 (高度简化的)界面是: internal interface IRepository w
我正在尝试实现一个通用的 GetById(T id) 方法,该方法将满足可能具有不同 ID 类型的类型。在我的示例中,我有一个实体,其 ID 类型为 int,其中一个 ID 类型为 string。 但
我在我的应用程序中使用 CKeditor-4,在我的编码中我想通过它的 id 获取元素。下面的代码在 FF 和 IE 中返回元素,但在 Google Chrome 中返回 null。 var ele
我尝试使用 getById() 函数获取 Raphaël 对象,但是无论我尝试什么,该函数都会返回 null。 这是我正在使用的 Raphaël JS 代码: // Creates canvas 32
我知道有一个问题名为:Ember data: what is difference between find and findById? .但是,如果我错了,请更正,但我认为它与旧版本的 Ember
我正在尝试使用 Entity Framework 实现通用存储库。 我的存储库定义为: public class GenericRepository : IRepository where T
我是一名优秀的程序员,十分优秀!