嘿,我正在用 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)