How to use the equal function from should

Find comprehensive JavaScript should.equal code examples handpicked from public code repositorys.

should.equal is an assertion method in the Should.js library that checks if two values are equal.

22
23
24
25
26
27
28
29
30
describe('test prepareZone', function () {
    it('test prepareZone', function (done) {
        config.zone = qiniu.zone.Zone_z0;
        qiniu.util.prepareZone(bucketManager, bucketManager.mac.accessKey, bucket, function (err, ctx) {
            should.not.exist(err);
            should.equal(bucketManager, ctx);
            done();
        });
    });
fork icon189
star icon577
watch icon38

+ 19 other calls in file

22
23
24
25
26
27
28
29
30
31
    var options = {
      source: path.join(__dirname, '/openapi_files/openapi1.yaml'),
      destination: path.join(__dirname, '../../api_bundles')
    }
    generateApi.generateApi('petStore', options, function (err, reply) {
      should.equal(err, null)
      done()
    })
  })
})
fork icon45
star icon30
watch icon0

+ 9 other calls in file

How does should.equal work?

should.equal is a function provided by the testing library "Should.js" that tests whether the actual value is equal to the expected value using strict equality (===).

66
67
68
69
70
71
72
73
74
    return remoteConfig.getConfigObject(context); 
  };
    
  const results = await Promise.all([cached(), notCached()]);
    
  should.equal(configObject.result.key5,'newvalue');
  should.notDeepEqual(results[0], configObject);
  should.deepEqual(results[1], configObject);
});
fork icon1
star icon3
watch icon0

+ 2 other calls in file

137
138
139
140
141
142
143
144
145
146
  remoteObject.getFresh(context)
    .then((result) => {
      done(new Error('Should not resolve when url is invalid.'));
    })
    .catch((err) => {
      should.equal(err, `Error calling url ${invalidObjectUrl}.`);
      done();
    })
    .catch(done);
});
fork icon1
star icon3
watch icon0

+ 7 other calls in file

Ai Example

1
2
3
4
5
6
7
8
9
10
const should = require("should");

describe("Math", function () {
  describe("#addition()", function () {
    it("should return the sum of two numbers", function () {
      const result = 1 + 2;
      should.equal(result, 3);
    });
  });
});

In this example, should.equal is used to assert that the value of result is equal to 3. If the assertion fails, an error will be thrown and the test case will fail.

72
73
74
75
76
77
78
79
80
  relativePath = './lib/absF.js',
  modF = join(root, 'node_modules/mod', 'modF.js'),
  modF2 = join(root, 'node_modules/mod2/lib', 'index.js');

assert.equal(requireResolve(absF, f), null);
assert.equal(requireResolve(relativePath, f), null);
assert.equal(requireResolve(modF, f), null);
assert.equal(requireResolve('mod2', f), null);
assert.equal(requireResolve('mod2/lib', f), null);
fork icon0
star icon7
watch icon0

+ 8 other calls in file

20
21
22
23
24
25
26
27
28
29
  should.notEqual(WeiboUtil.id2Mid(id), mid);
});

it('should null when id is invalid string', function() {
  const id = '&^%$%^&';
  should.equal(WeiboUtil.id2Mid(id), null);
});

it('should null when id is ""', function() {
  const id = '';
fork icon1
star icon2
watch icon0

+ 10 other calls in file

262
263
264
265
266
267
268
269
270
271
}

// Set assertions on new article
(articleSaveRes.body.title).should.equal(article.title);
should.exist(articleSaveRes.body.user);
should.equal(articleSaveRes.body.user._id, orphanId);

// force the article to have an orphaned user reference
orphan.remove(function () {
  // now signin with valid user
fork icon0
star icon1
watch icon1

+ 11 other calls in file

163
164
165
166
167
168
169
170
171
172
const jsonResponse = res.body;
should.exist(jsonResponse.posts);
localUtils.API.checkResponse(jsonResponse, 'posts');
jsonResponse.posts.should.have.length(13);

should.equal(jsonResponse.posts[0].meta_description, null);
jsonResponse.posts[12].slug.should.equal('short-and-sweet');
jsonResponse.posts[12].meta_description.should.equal('meta description for short and sweet');

localUtils.API.checkResponse(
fork icon0
star icon1
watch icon0

+ 10 other calls in file

47
48
49
50
51
52
53
54
55
56
        trialDays: 12
    });

    should.not.exist(mockStripe.checkout.sessions.create.firstCall.firstArg.subscription_data.trial_from_plan);
    should.exist(mockStripe.checkout.sessions.create.firstCall.firstArg.subscription_data.trial_period_days);
    should.equal(mockStripe.checkout.sessions.create.firstCall.firstArg.subscription_data.trial_period_days, 12);
});

it('createCheckoutSession uses trial_from_plan without trialDays', async function (){
    await api.createCheckoutSession('priceId', null, {});
fork icon0
star icon0
watch icon1

+ 15 other calls in file

119
120
121
122
123
124
125
126
127
128
    'members_subscribe_events'
];

excludedTables.forEach((tableName) => {
    // NOTE: why is this undefined? The key should probably not even be present
    should.equal(exportData.data[tableName], undefined);
});

// excludes settings with sensitive data
const excludedSettings = [
fork icon0
star icon0
watch icon1

157
158
159
160
161
162
163
164
165
166
        .expect('Content-Type', /json/)
        .expect('Cache-Control', testUtils.cacheRules.private)
        .expect(200);

    const jsonResponse = res.body;
    should.equal(jsonResponse.meta.pagination.page, 2);
});

it('Can request a post by id', async function () {
    const res = await request.get(localUtils.API.getApiQuery('posts/' + testUtils.DataGenerator.Content.posts[0].id + '/'))
fork icon0
star icon0
watch icon1

97
98
99
100
101
102
103
104
105
106

    addFixturesForModelStub.callCount.should.eql(fixtures.models.length);
    addFixturesForRelationStub.callCount.should.eql(fixtures.relations.length);

    // NOTE: users and roles have to be initialized first for the post fixtures to work
    should.equal(addFixturesForModelStub.firstCall.args[0].name, 'Role');
    should.equal(addFixturesForModelStub.secondCall.args[0].name, 'User');

    should.equal(addFixturesForRelationStub.firstCall.args[0].from.relation, 'roles');
});
fork icon0
star icon0
watch icon0

+ 11 other calls in file