【问题标题】:Legacy octal literals are not allowed in strict mode in cypresscypress 的严格模式下不允许使用旧式八进制文字
【发布时间】:2019-03-05 14:04:30
【问题描述】:

我使用 cypress 为 POST 方法编写了一个测试用例,并且我有一个 datetime 变量,如果我像 datetime 一样传递并且它以 0 开头,它会给我 Legacy octal literals are not allowed 编译错误。

这是测试脚本

describe('Create New Patient', function(){
    it('Creates new patient', function(){
        cy
        .request('POST', 'http://localhost:5002/api/v1/patients', { first_name: 'Jane', last_name: 'Dane', date_of_birth: 03041990 })
    .then((response) => {
        expect(response.body).to.have.property('first_name', 'Jane') // true
      expect(response.status).to.eq(200)
        })
    })
})

【问题讨论】:

    标签: ruby-on-rails api cypress octal web-api-testing


    【解决方案1】:

    它使用 parseInt

    工作
      body: { first_name: 'Jane', last_name: 'Dane', date_of_birth: parseInt('19920704')}
    

    【讨论】:

      【解决方案2】:

      为什么不使用 moment() 并将变量添加到请求中?像这样的:

      date = moment('1990-04-02', 'DDMMYYYY')
      describe('Create New Patient', function(){
          it('Creates new patient', function(){
              cy
              .request('POST', 'http://localhost:5002/api/v1/patients', { first_name: 'Jane', last_name: 'Dane', date_of_birth: date })
          .then((response) => {
              expect(response.body).to.have.property('first_name', 'Jane') // true
            expect(response.status).to.eq(200)
              })
          })
      })
      

      【讨论】:

      • 感谢您的回复,但没有成功。这是响应 Uncaught ReferenceError: moment is not defined 此错误源自您的测试代码,而不是赛普拉斯。当赛普拉斯检测到源自您的测试代码的未捕获错误时,它将自动使当前测试失败。赛普拉斯无法将此错误与任何特定测试相关联。我们动态生成了一个新的测试来显示这个失败。检查您的控制台以获取堆栈跟踪或单击此消息以查看它的来源。
      • @Ruby4Rails 你应该安装 moment 然后再试一次。
      猜你喜欢
      • 2016-08-21
      • 2021-03-31
      • 2021-08-18
      • 1970-01-01
      • 2014-06-29
      • 2018-11-11
      • 1970-01-01
      • 2021-08-29
      • 1970-01-01
      相关资源
      最近更新 更多