Skip to content

Commit

Permalink
test/ - remove should, use expect
Browse files Browse the repository at this point in the history
  • Loading branch information
bmacnaughton committed Nov 30, 2019
1 parent 6cfeea0 commit adcdbdb
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 48 deletions.
19 changes: 10 additions & 9 deletions test/http-events.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ var TEST_VALUE = 0x1337;
var PORT = 55667;

var chai = require('chai');
const expect = chai.expect;

var sinon = require('sinon');
var sinonChai = require('sinon-chai');
chai.should();
chai.use(sinonChai);

describe('cls with http connections', function () {
Expand Down Expand Up @@ -69,34 +70,34 @@ describe('cls with http connections', function () {
});


})
});

it('server request event should be called', () => {
requestSpy.called.should.be.true;
expect(requestSpy.called).true;
});

it('server request event should receive data', () => {
requestSpy.should.have.been.calledWith(TEST_VALUE);
expect(requestSpy).calledWith(TEST_VALUE);
});

it('server request data event should be called', () => {
requestDataSpy.called.should.be.true;
expect(requestDataSpy.called).true;
});

it('server request data event should receive data', () => {
requestDataSpy.should.have.been.calledWith(DATUM1, TEST_VALUE);
expect(requestDataSpy).calledWith(DATUM1, TEST_VALUE);
});

it('client data event should be called', () => {
responseSpy.called.should.be.true;
expect(responseSpy.called).true;
});

it('client data event should receive data', () => {
responseDataSpy.should.have.been.calledWith(DATUM2, 'MONKEY');
expect(responseDataSpy).calledWith(DATUM2, 'MONKEY');
});

it('final context value should be ' + TEST_VALUE, () => {
finalContextValue.should.be.equal(TEST_VALUE);
expect(finalContextValue).equal(TEST_VALUE);
});

});
Expand Down
14 changes: 6 additions & 8 deletions test/namespaces-multiple-values.test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
'use strict';

require('mocha');
const chai = require('chai');
const util = require('util');
chai.should();
const expect = require('chai').expect;
//const util = require('util');

const cls = require('../index.js');

Expand Down Expand Up @@ -59,19 +57,19 @@ describe('multiple namespaces handles them correctly', () => {
});

it('name tom1', () => {
test1Val.should.equal('tom1');
expect(test1Val).equal('tom1');
});

it('name paul2', () => {
test2Val.should.equal('paul2');
expect(test2Val).equal('paul2');
});

it('name bob', () => {
test3Val.should.equal('bob');
expect(test3Val).equal('bob');
});

it('name alice', () => {
test4Val.should.equal('alice');
expect(test4Val).equal('alice');
});

});
Expand Down
29 changes: 12 additions & 17 deletions test/namespaces.test.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
'use strict';

const chai = require('chai');
const should = chai.should();
const expect = chai.expect;

const context = require('../index.js');

chai.config.includeStack = true;


describe('cls namespace management', () => {

it('name is required', () => {
should.Throw(() => {
context.createNamespace();
});
expect(() => context.createNamespace()).throws;
});

let namespaceTest;
Expand All @@ -21,37 +19,34 @@ describe('cls namespace management', () => {
});

it('namespace is returned upon creation', () => {
should.exist(namespaceTest);
expect(namespaceTest).exist;
});

it('namespace lookup works', () => {
should.exist(context.getNamespace('test'));
context.getNamespace('test').should.be.equal(namespaceTest);
const ns = context.getNamespace('test');
expect(ns).equal(namespaceTest);
});

it('allows resetting namespaces', () => {
should.not.Throw(() => {
context.reset();
});
expect(() => context.reset()).not.throw();
});

it('namespaces have been reset', () => {
Object.keys(process.namespaces).length.should.equal(0);
const n = Object.keys(process.namespaces).length;
expect(n).equal(0, `process.namespaces.length is ${n}, not 0`);
});

it('namespace is available from global', () => {
context.createNamespace('another');
should.exist(process.namespaces.another);
expect(process.namespaces.another).exist;
});

it('destroying works', () => {
should.not.Throw(() => {
context.destroyNamespace('another');
});
expect(() => context.destroyNamespace('another')).not.throw();
});

it('namespace has been removed', () => {
should.not.exist(process.namespaces.another);
expect(process.namespaces.another).not.exist;
});

});
16 changes: 5 additions & 11 deletions test/net-events.test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
'use strict';

require('mocha');
const chai = require('chai');
const should = chai.should();
const expect = require('chai').expect;
const net = require('net');
const cls = require('../index.js');

Expand Down Expand Up @@ -73,23 +71,19 @@ describe('cls with net connection', () => {
});

it('value newContextValue', () => {
should.exist(testValue1);
testValue1.should.equal('newContextValue');
expect(testValue1).equal('newContextValue');
});

it('value newContextValue 2', () => {
should.exist(testValue2);
testValue2.should.equal('newContextValue');
expect(testValue2).equal('newContextValue');
});

it('value MONKEY', () => {
should.exist(testValue3);
testValue3.should.equal('MONKEY');
expect(testValue3).equal('MONKEY');
});

it('value MONKEY 2', () => {
should.exist(testValue4);
testValue4.should.equal('MONKEY');
expect(testValue4).equal('MONKEY');
});

});
5 changes: 2 additions & 3 deletions test/promise-context-convention.spec.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
'use strict';

require('mocha');
const chai = require('chai');
const should = chai.should();
const expect = chai.expect;

const context = require('../index.js');

Expand Down Expand Up @@ -38,7 +37,7 @@ describe('Promise context convention', () => {
});

it('convention should be 3', () => {
should.equal(conventionId, 3);
expect(conventionId).equal(3);
});

});

0 comments on commit adcdbdb

Please sign in to comment.