Throw error if you add a custom matcher or equality outside of a runnable
[#66789174]
This commit is contained in:
@@ -416,10 +416,16 @@ getJasmineRequireObj().Env = function(j$) {
|
||||
};
|
||||
|
||||
this.addCustomEqualityTester = function(tester) {
|
||||
if(!currentRunnable()) {
|
||||
throw new Error('Custom Equalities must be added in a before function or a spec');
|
||||
}
|
||||
runnableResources[currentRunnable().id].customEqualityTesters.push(tester);
|
||||
};
|
||||
|
||||
this.addMatchers = function(matchersToAdd) {
|
||||
if(!currentRunnable()) {
|
||||
throw new Error('Matchers must be added in a before function or a spec');
|
||||
}
|
||||
var customMatchers = runnableResources[currentRunnable().id].customMatchers;
|
||||
for (var matcherName in matchersToAdd) {
|
||||
customMatchers[matcherName] = matchersToAdd[matcherName];
|
||||
|
||||
@@ -825,4 +825,51 @@ describe("Env integration", function() {
|
||||
|
||||
env.execute();
|
||||
});
|
||||
|
||||
it('throws an exception if you try to add a matcher outside of a runnable', function (done) {
|
||||
var env = new j$.Env(),
|
||||
obj = {fn: function () {}},
|
||||
exception;
|
||||
|
||||
env.describe("a suite", function () {
|
||||
try {
|
||||
env.addMatchers({myMatcher: function(actual,expected){return false;}});
|
||||
} catch(e) {
|
||||
exception = e;
|
||||
}
|
||||
});
|
||||
|
||||
var assertions = function() {
|
||||
expect(exception.message).toBe('Matchers must be added in a before function or a spec');
|
||||
done();
|
||||
};
|
||||
|
||||
env.addReporter({jasmineDone: assertions});
|
||||
|
||||
env.execute();
|
||||
});
|
||||
|
||||
it('throws an exception if you try to add a custom equality outside of a runnable', function (done) {
|
||||
var env = new j$.Env(),
|
||||
obj = {fn: function () {}},
|
||||
exception;
|
||||
|
||||
env.describe("a suite", function () {
|
||||
try {
|
||||
env.addCustomEqualityTester(function(first, second) {return true;});
|
||||
} catch(e) {
|
||||
exception = e;
|
||||
}
|
||||
});
|
||||
|
||||
var assertions = function() {
|
||||
expect(exception.message).toBe('Custom Equalities must be added in a before function or a spec');
|
||||
done();
|
||||
};
|
||||
|
||||
env.addReporter({jasmineDone: assertions});
|
||||
|
||||
env.execute();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@@ -42,10 +42,16 @@ getJasmineRequireObj().Env = function(j$) {
|
||||
};
|
||||
|
||||
this.addCustomEqualityTester = function(tester) {
|
||||
if(!currentRunnable()) {
|
||||
throw new Error('Custom Equalities must be added in a before function or a spec');
|
||||
}
|
||||
runnableResources[currentRunnable().id].customEqualityTesters.push(tester);
|
||||
};
|
||||
|
||||
this.addMatchers = function(matchersToAdd) {
|
||||
if(!currentRunnable()) {
|
||||
throw new Error('Matchers must be added in a before function or a spec');
|
||||
}
|
||||
var customMatchers = runnableResources[currentRunnable().id].customMatchers;
|
||||
for (var matcherName in matchersToAdd) {
|
||||
customMatchers[matcherName] = matchersToAdd[matcherName];
|
||||
|
||||
Reference in New Issue
Block a user