小编Vin*_*hta的帖子

如何使用 mongoose 从 mongodb 模式中删除索引?

我正在尝试使用 mongoose 从 node.js 应用程序中的 mongoDB 集合中删除索引。我尝试使用,model.collection.dropIndex("username")但它给了我一个错误UnhandledPromiseRejectionWarning: MongoError: index not found with name [username]

这是我的架构

var mongoose = require("mongoose"),
  Schema = mongoose.Schema;

var userTable = new Schema({
  firstname: { type: String, required: true },
  lastname: { type: String, required: true },
  username: { type: String },
  salt: { type: String },
  passwordHash: { type: String },
  email: { type: String, unique: true, required: true },
  sessionToken: { type: String },
  dateCreated: { type: String, default: new …
Run Code Online (Sandbox Code Playgroud)

javascript mongoose node.js

3
推荐指数
1
解决办法
5528
查看次数

当我使用 jest 从模拟的 axios 调用返回一些响应时变得未定义

我正在尝试模拟 axios 调用并验证响应,但是当我记录来自模拟 axios 调用的响应时,我得到undefined. 任何人有任何想法为什么?

用户.js

import axios from 'axios';

export default class MyClass{
   constructor(config){
      this.config = config;
   }

   async getUsers(url, params, successHandler, errorHandler) {
      return axios.post(url, params)
             .then(resp => this.handleAPIResponse.call(this, resp, successHandler, errorHandler))
             .catch(error => errorHandler);
   }
}
Run Code Online (Sandbox Code Playgroud)

用户.test.js

import MyClass from './mycode.js';
import axios from 'axios';

jest.mock('axios');

beforeEach(() => {
  myClass = new MyClass({ env: 'prod' });
});

afterEach(() => {
  jest.clearAllMocks();
});

const mockResponseData = jest.fn((success, payload) => {
  return {
    data: {
      result: …
Run Code Online (Sandbox Code Playgroud)

javascript unit-testing jestjs axios

2
推荐指数
1
解决办法
1753
查看次数

标签 统计

javascript ×2

axios ×1

jestjs ×1

mongoose ×1

node.js ×1

unit-testing ×1