gpt4 book ai didi

javascript - 不应该按预期工作

转载 作者:行者123 更新时间:2023-12-03 02:12:42 26 4
gpt4 key购买 nike

我是Should 测试的新手。一直使用 Assert,但我正在尝试新的选项。

这个简单的测试不起作用,我很好奇为什么。

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

});

});

但我收到以下错误:

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)

这里出了什么问题?我错过了什么吗?

最佳答案

您必须使用profile.should.match。因为两个对象的原型(prototype)是不同的。您可以通过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);
});

});

});

关于javascript - 不应该按预期工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49489594/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com