【问题标题】:How to create a Unit test that should exclude extraneous dto properties?如何创建应排除无关 dto 属性的单元测试?
【发布时间】:2021-05-13 23:07:12
【问题描述】:

class SampleDTO {
    public readonly code: string
    public readonly name: string
    public readonly type: string
}

const sampleBodyRequest = {
    code: 'NZD',
    name: 'New Zealand dollar',
    type: 'fiat',
    color: 'white'
}

describe('validate', () => {

    it('should exclude extraneous dto properties', () => {
        
    })
})
有没有一种简单的方法来创建这个断言?

只需 mocha 和 sinon。提前致谢

【问题讨论】:

    标签: node.js unit-testing mocha.js sinon


    【解决方案1】:

    类似这样的:

    const assert = require('assert');
    ...
    describe('validate', () => {
    
        it('should exclude extraneous dto properties', () => {
           const expected = Object.getOwnPropertyNames(new SampleDTO());
           const actual = Object.getOwnPropertyNames(theFunctionUnderTestThatConvertsTheInputToDTO(sampleBodyRequest));
           assert.deepStrictEqual(actual, expected);        
        })
    })
    
    

    【讨论】:

      猜你喜欢
      • 2016-01-11
      • 2020-07-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-03-08
      • 1970-01-01
      • 2016-12-06
      • 1970-01-01
      相关资源
      最近更新 更多