例如这是列表:lst = ["69.78","","20.60","14.70","8.20","14.20","7.70","15.30"]
我怎么期望lst
包含字符串类型的项目?
例如,这应该失败:[1,5,2]
和['5', 2, '1']
答案 0 :(得分:1)
您可以遍历数组并在每个项目上调用isString
:
const { assert } = require('chai');
lst.forEach(item => assert.isString(item));
答案 1 :(得分:0)
或者您可以使用expect
const { expect } = require('chai');
lst.forEach(item => expect(item).to.be.a('string'))
答案 2 :(得分:0)
检查是否有非字符串项
const notStrings = lst.filter(n => typeof n !== 'string')
expect(notStrings.length).to.equal(0);