Skip to content

Commit

Permalink
Linting (#6)
Browse files Browse the repository at this point in the history
* Install linting deps

* Set linting config

* Make linting changes
  • Loading branch information
rkclark authored Dec 13, 2018
1 parent 9bafdd8 commit 1ef2e54
Show file tree
Hide file tree
Showing 6 changed files with 414 additions and 94 deletions.
21 changes: 14 additions & 7 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
{
"env": {
"node": true,
"es6": true,
"jest": true
},
"extends": "eslint:recommended"
}
"env": {
"node": true,
"es6": true,
"jest": true
},
"extends": ["airbnb-base", "prettier"],
"plugins": ["prettier"],
"rules": {
"prettier/prettier": [
"error",
{ "singleQuote": true, "trailingComma": "all" }
]
}
}
66 changes: 43 additions & 23 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"use strict";
/* eslint-disable no-underscore-dangle */

const equal = require('deep-equal');

module.exports = (chai) => {
const Assertion = chai.Assertion;
module.exports = chai => {
const { Assertion } = chai;
const MAX_TIMEOUT = 2000;

function promisfyNockInterceptor(nock) {
Expand Down Expand Up @@ -36,36 +36,56 @@ module.exports = (chai) => {

function isNock(obj) {
if (
typeof(obj) !== 'object' ||
!obj.interceptors ||
!obj.interceptors.length)
{
typeof obj !== 'object' ||
!obj.interceptors ||
!obj.interceptors.length
) {
throw new TypeError('You must provide a valid Nock');
}
}
}

Assertion.addProperty('requested', function () {
Assertion.addProperty('requested', () => {
isNock(this._obj);
const assert = (value) => {
this.assert(value, 'expected Nock to have been requested', 'expected Nock to have not been requested');
}

return promisfyNockInterceptor(this._obj)
.then(
() => assert(true),
() => assert(false)
const assert = value => {
this.assert(
value,
'expected Nock to have been requested',
'expected Nock to have not been requested',
);
};

return promisfyNockInterceptor(this._obj).then(
() => assert(true),
() => assert(false),
);
});

Assertion.addMethod('requestedWith', function (arg) {
Assertion.addMethod('requestedWith', arg => {
isNock(this._obj);

return promisfyNockInterceptor(this._obj)
.then((nockRequest) => {
return promisfyNockInterceptor(this._obj).then(
nockRequest => {
if (equal(nockRequest, arg)) {
return this.assert(true, null, 'expected Nock to have not been requested with #{exp}', arg);
return this.assert(
true,
null,
'expected Nock to have not been requested with #{exp}',
arg,
);
}
return this.assert(false, 'expected Nock to have been requested with #{exp}, but was requested with #{act}', 'expected Nock to have not been requested with #{exp}', arg, nockRequest);
},() => this.assert(false, 'expected Nock to have been requested, but it was never called'));
return this.assert(
false,
'expected Nock to have been requested with #{exp}, but was requested with #{act}',
'expected Nock to have not been requested with #{exp}',
arg,
nockRequest,
);
},
() =>
this.assert(
false,
'expected Nock to have been requested, but it was never called',
),
);
});
};
240 changes: 240 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 1ef2e54

Please sign in to comment.