gpt4 book ai didi

javascript - 类型错误 : Attempted to wrap undefined property query as function

转载 作者:行者123 更新时间:2023-11-29 03:23:14 25 4
gpt4 key购买 nike

我正在尝试制作一个模拟数据库驱动程序的简单基本示例(稍后用于测试):

'use strict';
import mysql from 'mysql';
import sinon from 'sinon';

let mock = sinon.mock(mysql);

mock.expects('query').withExactArgs(`DROP DATABASE IF EXISTS myDatabase`).yields({ "fieldCount": 0, "affectedRows": 1, "insertId": 0, "serverStatus": 258, "warningCount": 0, "message": "", "protocol41": true, "changedRows": 0 });

mysql.query('DROP DATABASE IF EXISTS myDatabase');

我得到错误:

TypeError: Attempted to wrap undefined property query as function

最佳答案

从文档看来,您使用 mysql.createConnection() 返回一个连接,然后可以调用 connection.query。

'use strict';
import mysql from 'mysql';
import sinon from 'sinon';

let mock = sinon.mock(mysql.createConnection());

mock.expects('query').withExactArgs(`DROP DATABASE IF EXISTS myDatabase`).yields({ "fieldCount": 0, "affectedRows": 1, "insertId": 0, "serverStatus": 258, "warningCount": 0, "message": "", "protocol41": true, "changedRows": 0 });

mysql.query('DROP DATABASE IF EXISTS myDatabase');

关于javascript - 类型错误 : Attempted to wrap undefined property query as function,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40549124/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com