0

I am new to Should testing. Always used Assert but I'm trying new options.

This simple test is not working and I am curious to understand why.

Profile.js

class Profile {

    constructor(profile_name,user_name,email,language) {
        this.profile_name = profile_name;
        this.user_name = user_name;
        this.email = email;
        this.language = language;
    }

}

module.exports = Profile;

Profile_test.js

let should = require('should');

let Profile = require('../lib/entities/Profile');

describe('Profile', function() {

    describe('#constructor', function() {

        it('should return a Profile object', function() {
            let profile = new Profile('alfa','Alfa da Silva','alfa@beta.com','java');
            let valid = { profile_name: 'alfa', user_name: 'Alfa da Silva', email: 'alfa@beta.com', language: 'java'};
            profile.should.equal(valid);
        });

    });

});

But I am getting the following error:

Profile #constructor 1) should return a Profile object

0 passing (62ms) 1 failing

1) Profile #constructor should return a Profile object:

 AssertionError: expected Profile {

profile_name: 'alfa', user_name: 'Alfa da Silva', email: 'alfa@beta.com', language: 'java' } to be Object { profile_name: 'alfa', user_name: 'Alfa da Silva', email: 'alfa@beta.com', language: 'java' } + expected - actual

 at Assertion.fail (node_modules/should/cjs/should.js:275:17)
 at Assertion.value (node_modules/should/cjs/should.js:356:19)
 at Context.<anonymous> (test/Profile_test.js:12:19)

What is wrong here? Am I missing something?

Ed de Almeida
  • 3,675
  • 4
  • 25
  • 57

2 Answers2

1

You have to use profile.should.match. Because the prototype of two object is different. You can get information from here.

 let should = require('should');

let Profile = require('../lib/entities/Profile');

describe('Profile', function() {

    describe('#constructor', function() {

        it('should return a Profile object', function() {
            let profile = new Profile('alfa','Alfa da Silva','alfa@beta.com','java');
            let valid = { profile_name: 'alfa', user_name: 'Alfa da Silva', email: 'alfa@beta.com', language: 'java'};
            profile.should.match(valid);
        });

    });

});
Chinmoy Samanta
  • 1,376
  • 7
  • 17
0

Yes. From should documentation

should.equal(actual, expected, [message])

Node.js standard assert.equal.

And from Nodejs documentation we know that assert.equal(...)

Tests shallow, coercive equality between the actual and expected parameters using the Abstract Equality Comparison ( == ).

Looks like you need to use eql(..) or deepEqual(..). Something like

profile.should.be.eql(valid);
Community
  • 1
  • 1
Vasyl Moskalov
  • 4,242
  • 3
  • 20
  • 28