小编Fre*_*sen的帖子

测试后反应cypress json-server恢复到原始数据库

嘿,我正在用 cypress 测试 React 应用程序,并使用 json-server 来测试一个假 api。

当我运行一些测试时,它将更改我的 db.json 文件的数据库。

因此计划是在每次测试后将数据库恢复到原始状态。

这是我的代码:

describe('Testing fake db to be restored to original database after 
updating it in other test', () => {

 let originalDb: any = null

    it('Fetch the db.json file and then updating it to the original copy', 
       () => {

      // Save a copy of the original database
      cy.request('GET', 'localhost:8000/db').then(response => {
         originalDb = response;
         console.log(originalDb);
       })

    // Restore the original database
    cy.wrap(originalDb).then(db => {
      cy.request({
        method: 'PUT',
        url: …
Run Code Online (Sandbox Code Playgroud)

testing request reactjs json-server cypress

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

标签 统计

cypress ×1

json-server ×1

reactjs ×1

request ×1

testing ×1