Skip to content
This repository has been archived by the owner on Jun 11, 2024. It is now read-only.

Commit

Permalink
Use this instead of self context in SchemaDynamicTests
Browse files Browse the repository at this point in the history
closes #802
  • Loading branch information
MaciejBaj authored and diego-G committed Sep 26, 2017
1 parent 010b9e5 commit 6029fb7
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions test/common/schemaDynamicTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ function SchemaDynamicTest (config) {
}
}
},
shouldFailWithoutRequiredProperties: self.testRequired
shouldFailWithoutRequiredProperties: self.testRequired.bind(self)
};
}

Expand All @@ -113,29 +113,29 @@ SchemaDynamicTest.prototype.standardInvalidPropertyAssertion = function (input,
};

SchemaDynamicTest.prototype.testArgument = function (expectedType, invalidInputs, testedFunction) {
var assertion = self.customArgumentAssertion ? self.customArgumentAssertion.bind(self) : self.standardInvalidArgumentAssertion;
var assertion = this.customArgumentAssertion || this.standardInvalidArgumentAssertion;
var test = function (invalidInput, eachCb) {
self.testStyle(testedFunction, invalidInput.input, function (err) {
this.testStyle(testedFunction, invalidInput.input, function (err) {
assertion(invalidInput, expectedType, err);
eachCb();
});
};
self.carpetTesting(test, invalidInputs, 'should return an error when invoked with %s');
}.bind(this);
this.carpetTesting(test, invalidInputs, 'should return an error when invoked with %s');
};

SchemaDynamicTest.prototype.testProperty = function (expectedType, invalidInputs, testedFunction, validArgument, property) {
var assertion = self.customPropertyAssertion ? self.customPropertyAssertion.bind(self) : self.standardInvalidPropertyAssertion;
var assertion = this.customPropertyAssertion || this.standardInvalidPropertyAssertion;
var test = function (invalidInput, eachCb) {
var malformedPart = {};
set(malformedPart, property, invalidInput.input);

var invalidArgument = assign({}, validArgument, malformedPart);
self.testStyle(testedFunction, invalidArgument, function (err) {
this.testStyle(testedFunction, invalidArgument, function (err) {
assertion(invalidInput, expectedType, property, err);
eachCb();
});
};
self.carpetTesting(test, invalidInputs, 'should return an error when ' + property + ' is %s');
}.bind(this);
this.carpetTesting(test, invalidInputs, 'should return an error when ' + property + ' is %s');
};

SchemaDynamicTest.prototype.standardMissingRequiredPropertiesAssertion = function (property, err) {
Expand All @@ -144,19 +144,19 @@ SchemaDynamicTest.prototype.standardMissingRequiredPropertiesAssertion = functio
};

SchemaDynamicTest.prototype.testRequired = function (testedFunction, validArgument, properties) {
var assertion = self.customRequiredPropertiesAssertion ? self.customRequiredPropertiesAssertion.bind(self) : self.standardMissingRequiredPropertiesAssertion;
var assertion = this.customRequiredPropertiesAssertion || this.standardMissingRequiredPropertiesAssertion;
var test = function (missingProperty, eachCb) {
var invalidArgument = assign({}, validArgument);
delete invalidArgument[missingProperty.description];
self.testStyle(testedFunction, invalidArgument, function (err) {
this.testStyle(testedFunction, invalidArgument, function (err) {
assertion(missingProperty.description, err);
eachCb();
});
};
}.bind(this);
var missingFieldsDescriptions = properties.map(function (property) {
return {description: property};
});
self.carpetTesting(test, missingFieldsDescriptions, 'should return an error when invoked without %s');
this.carpetTesting(test, missingFieldsDescriptions, 'should return an error when invoked without %s');
};

module.exports = SchemaDynamicTest;

0 comments on commit 6029fb7

Please sign in to comment.