小编Naz*_*hyn的帖子

在Cypress(mysql2)中测试时无法连接到MySQL数据库

运行集成测试时出现错误:

0 passing (17s)
   1 failure

   1) Registration page
        register new users allowed and update status in the database:
      TypeError: Net.connect is not a function
       at new Connection (webpack:///./node_modules/mysql2/lib/connection.js:50:0)
       at ./node_modules/mysql2/index.js.exports.createConnection (webpack:///./node_modules/mysql2/index.js:10:0)
       at Context.eval (webpack:///./cypress/integration/registration.spec.js:23:34)
Run Code Online (Sandbox Code Playgroud)

这是我的环境:

MySQL Workbench
MySQL Server 8.0.29
Run Code Online (Sandbox Code Playgroud)

我提出了本地后端,我可以访问数据库。这是我的代码:

const mysql2 = require('mysql2');

describe('Registration page', () => {
     beforeEach(() => {
         // visit the registration page
         cy.visit('http://localhost:3000/registration');
     });

     it('register new users allowed and update status in the database', () => {
         // fill out the registration form …
Run Code Online (Sandbox Code Playgroud)

mysql mysql2 cypress

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

标签 统计

cypress ×1

mysql ×1

mysql2 ×1