相关疑难解决方法(0)

如何使用cypress模拟vuex存储操作

我有一个登录过程,在向服务器发送请求并获得响应后,我执行以下操作:

 this.$auth.setToken(response.data.token);
 this.$store.dispatch("setLoggedUser", {
     username: this.form.username
 });
Run Code Online (Sandbox Code Playgroud)

现在,我想在使用赛普拉斯进行测试时模拟这种行为,因此我不需要每次运行测试时都实际登录。

所以我创建了一个命令:

Cypress.Commands.add("login", () => {
  cy
    .request({
      method: "POST",
      url: "http://localhost:8081/api/v1/login",
      body: {},
      headers: {
        Authorization: "Basic " + btoa("administrator:12345678")
      }
    })
    .then(resp => {
      window.localStorage.setItem("aq-username", "administrator");
    });

});
Run Code Online (Sandbox Code Playgroud)

但是我不知道如何模仿“ setLoggedUser”操作,有什么想法吗?

vue.js vuex cypress

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

标签 统计

cypress ×1

vue.js ×1

vuex ×1