【发布时间】:2020-12-31 02:56:19
【问题描述】:
我需要在我得到的 JS 对象上运行一个断言。这里的问题是,即使我的断言失败,测试仍然显示通过;我该如何解决?
代码:
var expect = require('chai').expect
const sslCertificate = require('get-ssl-certificate')
describe('ssl certificate verification',()=>{
it('verifies the issuer of the certificate',()=>{
sslCertificate.get('instagram.com').then(function (certificate) {
console.log(typeof certificate.issuer)
console.log(certificate.issuer.O)
console.log(certificate.issuer.CN)
console.log(certificate.subject.CN)
expect(certificate.issuer).to.include({CN: 'DigiCert SHA2 High Assurance Server CA'});
expect(certificate.issuer).which.is.an('object').to.haveOwnProperty('CN')
})
})
})
终端命令:
mocha myFile.js
输出
ssl certificate verification
√ verifies the issue of the certificate
1 passing (46ms)
object
DigiCert Inc
DigiCert SHA2 High Assurance Server CA
*.instagram.com
断言失败,但通过测试输出
expect(certificate.issuer).to.include({CN: 'a'});
ssl certificate verification
√ verifies the issue of the certificate
1 passing (43ms)
object
DigiCert Inc
DigiCert SHA2 High Assurance Server CA
*.instagram.com
(node:13712) UnhandledPromiseRejectionWarning: AssertionError: expected { Object (C, O, ...) } to have property 'CN' of 'a', but got 'DigiCert SHA2 High Assurance Server CA'
at D:\a10\cypress\integration\ssli5_2v4\bypassFlow\new.js:15:42
at processTicksAndRejections (internal/process/task_queues.js:97:5)
(node:13712) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:13712) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
【问题讨论】:
标签: node.js mocha.js assertion