问题描述
我试图检查传递的返回值,但是当我期望toHaveBeenCalledWith
相同的函数时,它会失败,并出现 no.of.call::0 。谁能告诉我这段代码有什么问题吗?
describe('buildAggregateParams',() => {
// Preparing
const schemaParams = {
filterKeyMap: {
id: '_id',name: 'test_name',no: '_no',},sortKeyMap: {
date: '_created_date',status: '_status_is_active',lookups: [
{
from: 'sample',localField: 'test_id',foreignField: '_id',as: 'test_id',model: 'sampleModel',],unwinds: [],queryKeys: ['page','size','sort','order_by','from','to','status'],};
const entityName = 'test_collection';
it('test 1.',async () => {
// Preparing
const request = ({
query: {
price_fromss: '2',originalUrl: '/api/m3/product/all/?price_fromss=2',} as unknown) as Request;
const expectBuildAggregateParamsResult = {
filters: { test_collection_status_is_active: true },pageSort: { limit: 25,skip: 0,sort: {} },filterKeyMap: { id: '_id',no: '_no' },sortKeyMap: {
date: '_created_date',lookups: [
{
from: 'sample',};
const ff = jest.spyOn(ControllerUtility,'buildAggregateParams');
// Executings
const result = await buildAggregateParams(request as Request,schemaParams,entityName,{
price_fromss: jest.fn(),});
expect(result).toEqual(expectBuildAggregateParamsResult); // Passed
expect(ff).toHaveBeenCalledWith(request as Request,}); //Failed
});
});
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)