赛普拉斯不允许在严格模式下使用旧八进制文字

时间:2019-03-05 14:04:30

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

我用cypress编写了一个POST方法的测试用例,我有一个datetime变量,如果我像datetime这样传递,并且它以0开头,就给我遗留的八进制文字不允许编译错误。

这是测试脚本

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)
        })
    })
})

2 个答案:

答案 0 :(得分:1)

它使用 parseInt

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

答案 1 :(得分:0)

为什么不使用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)
        })
    })
})
相关问题