我正在尝试使用 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) 我正在尝试模拟 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)