2

I'm using the deepEqual assertion, but my test fails

Test

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'}
    ]);
}

Fail output

 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"}]                   

Question

How do I fix this?

Édouard Lopez
  • 40,270
  • 28
  • 126
  • 178

1 Answers1

3

I had a type issue, the port value was a string on one side and an integer on the other…

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

In this case, both object are identical.

Édouard Lopez
  • 40,270
  • 28
  • 126
  • 178