Skip to content

Commit 6526a78

Browse files
committed
test: handling of sortAsync
1 parent 30c1874 commit 6526a78

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"types": "index.d.ts",
77
"scripts": {
88
"test": "mocha",
9-
"test:coverage" : "nyc npm test",
9+
"test:coverage": "nyc npm test",
1010
"coverage": "nyc npm test && nyc report --reporter=text-lcov | coveralls"
1111
},
1212
"repository": {
@@ -29,6 +29,7 @@
2929
"license": "ISC",
3030
"devDependencies": {
3131
"chai": "4.2.0",
32+
"chai-as-promised": "^7.1.1",
3233
"coveralls": "3.0.9",
3334
"mocha": "6.2.2",
3435
"nyc": "15.0.0",

test/index.test.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
const chai = require('chai');
2+
const chaiAsPromised = require("chai-as-promised")
23
const rewire = require("rewire");
34
const index = require('../index');
45
const main = rewire('../index');
56
const expect = chai.expect;
67
chai.should();
8+
chai.use(chaiAsPromised);
79

810
describe('asc & desc tests', () => {
911
let json0, json1, json2, json3;
@@ -418,4 +420,30 @@ describe('typeOf()', () => {
418420
const should = main.__get__("typeOf")(given);
419421
expect(should).to.equal("STRING");
420422
});
423+
});
424+
425+
describe('sortAsync', () => {
426+
427+
it('given invalid object : should be rejected', function () {
428+
const given = "string";
429+
return index.sortAsync(given).should.be.rejected;
430+
});
431+
432+
describe('given valid object : should sort successfully', function () {
433+
const given = {d: 1, a: 0};
434+
let result;
435+
436+
before(async () => {
437+
result = await index.sortAsync(given)
438+
})
439+
440+
it('expect key 1 to be a', function () {
441+
expect(Object.keys(result)[0]).to.equal("a")
442+
});
443+
444+
it('expect key 2 to be d', function () {
445+
expect(Object.keys(result)[1]).to.equal("d")
446+
});
447+
448+
});
421449
});

yarn.lock

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,13 @@ caseless@~0.12.0:
360360
resolved "https://registry.yarnpkg.com/caseless/-/caseless-0.12.0.tgz#1b681c21ff84033c826543090689420d187151dc"
361361
integrity sha1-G2gcIf+EAzyCZUMJBolCDRhxUdw=
362362

363+
chai-as-promised@^7.1.1:
364+
version "7.1.1"
365+
resolved "https://registry.yarnpkg.com/chai-as-promised/-/chai-as-promised-7.1.1.tgz#08645d825deb8696ee61725dbf590c012eb00ca0"
366+
integrity sha512-azL6xMoi+uxu6z4rhWQ1jbdUhOMhis2PvscD/xjLqNMkv3BPPp2JyyuTHOrf9BOosGpNQ11v6BKv/g57RXbiaA==
367+
dependencies:
368+
check-error "^1.0.2"
369+
363370
chai@4.2.0:
364371
version "4.2.0"
365372
resolved "https://registry.yarnpkg.com/chai/-/chai-4.2.0.tgz#760aa72cf20e3795e84b12877ce0e83737aa29e5"

0 commit comments

Comments
 (0)