2

deepEqualアサーションを使用していますが、テストが失敗します

テスト

test('should return list of printers', t => {
    const clipboard = filter.asClipboardContent(scan);

    t.is(clipboard, [
        {hostname: '10.0.1.1', port: '9100', description: 'HP 5020-NL'},
        {hostname: '10.0.1.8', port: '9100', description: 'Brother 4002'}
    ]);
}

失敗出力

 t.deepEqual(clipboard, [{ hostname: '10.0.1.1', port: '9100', description: 'HP 5020-NL' }, { hostname: '10.0.1.8', port: '9100', description: 'Brother 4002' }])
              |                                                                                                                                                   
              [Object{hostname:"10.0.1.1",port:9100,description:"HP 5020-NL"},Object{hostname:"10.0.1.8",port:9100,description:"Brother 4002"}]                   

質問

これを修正するにはどうすればよいですか?

4

1 に答える 1

3

型に問題がありました。port値はstring一方が a で、もう一方が a でしたinteger…</p>

test('should return list of printers', t => {
    const expected = [
        {hostname: '10.0.1.1', port: 9100, description: 'HP 5020-NL'},
        {hostname: '10.0.1.8', port: 9100, description: 'Brother 4002'}
    ];

    const clipboard = filter.asClipboardContent(scan);

    t.deepEqual(clipboard, expected);
});

この場合、両方のオブジェクトは同一です。

于 2016-09-16T15:30:28.750 に答える