Use mocha

This commit is contained in:
Tom MacWright 2013-03-01 16:49:20 -05:00 committed by John Firebaugh
parent b84be89095
commit a2f7d7e834
36 changed files with 11515 additions and 3869 deletions

View File

@ -32,7 +32,7 @@ function getFiles(compsBase32) {
if (compsBase32) { if (compsBase32) {
comps = parseInt(compsBase32, 32).toString(2).split(''); comps = parseInt(compsBase32, 32).toString(2).split('');
console.log('Managing dependencies...') console.log('Managing dependencies...');
} }
function addFiles(srcs) { function addFiles(srcs) {
@ -160,6 +160,8 @@ exports.test = function() {
testConfig = {configFile : __dirname + '/../spec/karma.conf.js'}; testConfig = {configFile : __dirname + '/../spec/karma.conf.js'};
testConfig.browsers = ['PhantomJS']; testConfig.browsers = ['PhantomJS'];
if (isArgv('--chrome')) testConfig.browsers.push('Chrome');
if (isArgv('--ff')) testConfig.browsers.push('Firefox');
if (isArgv('--chrome')) { if (isArgv('--chrome')) {
testConfig.browsers.push('Chrome'); testConfig.browsers.push('Chrome');
@ -170,7 +172,7 @@ exports.test = function() {
if (isArgv('--cov')) { if (isArgv('--cov')) {
testConfig.preprocessors = { testConfig.preprocessors = {
'**/src/**/*.js': 'coverage', '**/src/**/*.js': 'coverage'
}; };
testConfig.coverageReporter = { testConfig.coverageReporter = {
type : 'html', type : 'html',
@ -184,4 +186,4 @@ exports.test = function() {
function isArgv(optName) { function isArgv(optName) {
return process.argv.indexOf(optName) !== -1; return process.argv.indexOf(optName) !== -1;
} }
} };

1253
spec/expect.js Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,11 +1,16 @@
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
<title>Jasmine Spec Runner</title> <meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="jasmine/jasmine.css"> <title>Spec Runner</title>
<script type="text/javascript" src="jasmine/jasmine.js"></script> <link rel="stylesheet" type="text/css" href="mocha/mocha.css">
<script type="text/javascript" src="jasmine/jasmine-html.js"></script> </head>
<body>
<div id="mocha"></div>
<script src="expect.js"></script>
<script type="text/javascript" src="mocha/mocha.js"></script>
<script type="text/javascript" src="happen.js"></script> <script type="text/javascript" src="happen.js"></script>
<script type="text/javascript" src="sinon.js"></script>
<!-- source files --> <!-- source files -->
<script type="text/javascript" src="before.js"></script> <script type="text/javascript" src="before.js"></script>
@ -13,6 +18,10 @@
<script type="text/javascript" src="../debug/leaflet-include.js"></script> <script type="text/javascript" src="../debug/leaflet-include.js"></script>
<script>
mocha.setup('bdd');
mocha.ignoreLeaks();
</script>
<!-- spec files --> <!-- spec files -->
@ -59,22 +68,9 @@
<!-- /map --> <!-- /map -->
<script type="text/javascript" src="suites/map/MapSpec.js"></script> <script type="text/javascript" src="suites/map/MapSpec.js"></script>
</head>
<body>
<script type="text/javascript">
(function() {
var jasmineEnv = jasmine.getEnv();
jasmineEnv.updateInterval = 1000;
var htmlReporter = new jasmine.HtmlReporter(); <script>
jasmineEnv.addReporter(htmlReporter); (window.mochaPhantomJS || window.mocha).run();
</script>
jasmineEnv.specFilter = function(spec) {
return htmlReporter.specFilter(spec);
};
jasmineEnv.execute();
})();
</script>
</body> </body>
</html> </html>

View File

@ -1,20 +0,0 @@
Copyright (c) 2008-2011 Pivotal Labs
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View File

@ -1,681 +0,0 @@
jasmine.HtmlReporterHelpers = {};
jasmine.HtmlReporterHelpers.createDom = function(type, attrs, childrenVarArgs) {
var el = document.createElement(type);
for (var i = 2; i < arguments.length; i++) {
var child = arguments[i];
if (typeof child === 'string') {
el.appendChild(document.createTextNode(child));
} else {
if (child) {
el.appendChild(child);
}
}
}
for (var attr in attrs) {
if (attr == "className") {
el[attr] = attrs[attr];
} else {
el.setAttribute(attr, attrs[attr]);
}
}
return el;
};
jasmine.HtmlReporterHelpers.getSpecStatus = function(child) {
var results = child.results();
var status = results.passed() ? 'passed' : 'failed';
if (results.skipped) {
status = 'skipped';
}
return status;
};
jasmine.HtmlReporterHelpers.appendToSummary = function(child, childElement) {
var parentDiv = this.dom.summary;
var parentSuite = (typeof child.parentSuite == 'undefined') ? 'suite' : 'parentSuite';
var parent = child[parentSuite];
if (parent) {
if (typeof this.views.suites[parent.id] == 'undefined') {
this.views.suites[parent.id] = new jasmine.HtmlReporter.SuiteView(parent, this.dom, this.views);
}
parentDiv = this.views.suites[parent.id].element;
}
parentDiv.appendChild(childElement);
};
jasmine.HtmlReporterHelpers.addHelpers = function(ctor) {
for(var fn in jasmine.HtmlReporterHelpers) {
ctor.prototype[fn] = jasmine.HtmlReporterHelpers[fn];
}
};
jasmine.HtmlReporter = function(_doc) {
var self = this;
var doc = _doc || window.document;
var reporterView;
var dom = {};
// Jasmine Reporter Public Interface
self.logRunningSpecs = false;
self.reportRunnerStarting = function(runner) {
var specs = runner.specs() || [];
if (specs.length == 0) {
return;
}
createReporterDom(runner.env.versionString());
doc.body.appendChild(dom.reporter);
setExceptionHandling();
reporterView = new jasmine.HtmlReporter.ReporterView(dom);
reporterView.addSpecs(specs, self.specFilter);
};
self.reportRunnerResults = function(runner) {
reporterView && reporterView.complete();
};
self.reportSuiteResults = function(suite) {
reporterView.suiteComplete(suite);
};
self.reportSpecStarting = function(spec) {
if (self.logRunningSpecs) {
self.log('>> Jasmine Running ' + spec.suite.description + ' ' + spec.description + '...');
}
};
self.reportSpecResults = function(spec) {
reporterView.specComplete(spec);
};
self.log = function() {
var console = jasmine.getGlobal().console;
if (console && console.log) {
if (console.log.apply) {
console.log.apply(console, arguments);
} else {
console.log(arguments); // ie fix: console.log.apply doesn't exist on ie
}
}
};
self.specFilter = function(spec) {
if (!focusedSpecName()) {
return true;
}
return spec.getFullName().indexOf(focusedSpecName()) === 0;
};
return self;
function focusedSpecName() {
var specName;
(function memoizeFocusedSpec() {
if (specName) {
return;
}
var paramMap = [];
var params = jasmine.HtmlReporter.parameters(doc);
for (var i = 0; i < params.length; i++) {
var p = params[i].split('=');
paramMap[decodeURIComponent(p[0])] = decodeURIComponent(p[1]);
}
specName = paramMap.spec;
})();
return specName;
}
function createReporterDom(version) {
dom.reporter = self.createDom('div', { id: 'HTMLReporter', className: 'jasmine_reporter' },
dom.banner = self.createDom('div', { className: 'banner' },
self.createDom('span', { className: 'title' }, "Jasmine "),
self.createDom('span', { className: 'version' }, version)),
dom.symbolSummary = self.createDom('ul', {className: 'symbolSummary'}),
dom.alert = self.createDom('div', {className: 'alert'},
self.createDom('span', { className: 'exceptions' },
self.createDom('label', { className: 'label', 'for': 'no_try_catch' }, 'No try/catch'),
self.createDom('input', { id: 'no_try_catch', type: 'checkbox' }))),
dom.results = self.createDom('div', {className: 'results'},
dom.summary = self.createDom('div', { className: 'summary' }),
dom.details = self.createDom('div', { id: 'details' }))
);
}
function noTryCatch() {
return window.location.search.match(/catch=false/);
}
function searchWithCatch() {
var params = jasmine.HtmlReporter.parameters(window.document);
var removed = false;
var i = 0;
while (!removed && i < params.length) {
if (params[i].match(/catch=/)) {
params.splice(i, 1);
removed = true;
}
i++;
}
if (jasmine.CATCH_EXCEPTIONS) {
params.push("catch=false");
}
return params.join("&");
}
function setExceptionHandling() {
var chxCatch = document.getElementById('no_try_catch');
if (noTryCatch()) {
chxCatch.setAttribute('checked', true);
jasmine.CATCH_EXCEPTIONS = false;
}
chxCatch.onclick = function() {
window.location.search = searchWithCatch();
};
}
};
jasmine.HtmlReporter.parameters = function(doc) {
var paramStr = doc.location.search.substring(1);
var params = [];
if (paramStr.length > 0) {
params = paramStr.split('&');
}
return params;
}
jasmine.HtmlReporter.sectionLink = function(sectionName) {
var link = '?';
var params = [];
if (sectionName) {
params.push('spec=' + encodeURIComponent(sectionName));
}
if (!jasmine.CATCH_EXCEPTIONS) {
params.push("catch=false");
}
if (params.length > 0) {
link += params.join("&");
}
return link;
};
jasmine.HtmlReporterHelpers.addHelpers(jasmine.HtmlReporter);
jasmine.HtmlReporter.ReporterView = function(dom) {
this.startedAt = new Date();
this.runningSpecCount = 0;
this.completeSpecCount = 0;
this.passedCount = 0;
this.failedCount = 0;
this.skippedCount = 0;
this.createResultsMenu = function() {
this.resultsMenu = this.createDom('span', {className: 'resultsMenu bar'},
this.summaryMenuItem = this.createDom('a', {className: 'summaryMenuItem', href: "#"}, '0 specs'),
' | ',
this.detailsMenuItem = this.createDom('a', {className: 'detailsMenuItem', href: "#"}, '0 failing'));
this.summaryMenuItem.onclick = function() {
dom.reporter.className = dom.reporter.className.replace(/ showDetails/g, '');
};
this.detailsMenuItem.onclick = function() {
showDetails();
};
};
this.addSpecs = function(specs, specFilter) {
this.totalSpecCount = specs.length;
this.views = {
specs: {},
suites: {}
};
for (var i = 0; i < specs.length; i++) {
var spec = specs[i];
this.views.specs[spec.id] = new jasmine.HtmlReporter.SpecView(spec, dom, this.views);
if (specFilter(spec)) {
this.runningSpecCount++;
}
}
};
this.specComplete = function(spec) {
this.completeSpecCount++;
if (isUndefined(this.views.specs[spec.id])) {
this.views.specs[spec.id] = new jasmine.HtmlReporter.SpecView(spec, dom);
}
var specView = this.views.specs[spec.id];
switch (specView.status()) {
case 'passed':
this.passedCount++;
break;
case 'failed':
this.failedCount++;
break;
case 'skipped':
this.skippedCount++;
break;
}
specView.refresh();
this.refresh();
};
this.suiteComplete = function(suite) {
var suiteView = this.views.suites[suite.id];
if (isUndefined(suiteView)) {
return;
}
suiteView.refresh();
};
this.refresh = function() {
if (isUndefined(this.resultsMenu)) {
this.createResultsMenu();
}
// currently running UI
if (isUndefined(this.runningAlert)) {
this.runningAlert = this.createDom('a', { href: jasmine.HtmlReporter.sectionLink(), className: "runningAlert bar" });
dom.alert.appendChild(this.runningAlert);
}
this.runningAlert.innerHTML = "Running " + this.completeSpecCount + " of " + specPluralizedFor(this.totalSpecCount);
// skipped specs UI
if (isUndefined(this.skippedAlert)) {
this.skippedAlert = this.createDom('a', { href: jasmine.HtmlReporter.sectionLink(), className: "skippedAlert bar" });
}
this.skippedAlert.innerHTML = "Skipping " + this.skippedCount + " of " + specPluralizedFor(this.totalSpecCount) + " - run all";
if (this.skippedCount === 1 && isDefined(dom.alert)) {
dom.alert.appendChild(this.skippedAlert);
}
// passing specs UI
if (isUndefined(this.passedAlert)) {
this.passedAlert = this.createDom('span', { href: jasmine.HtmlReporter.sectionLink(), className: "passingAlert bar" });
}
this.passedAlert.innerHTML = "Passing " + specPluralizedFor(this.passedCount);
// failing specs UI
if (isUndefined(this.failedAlert)) {
this.failedAlert = this.createDom('span', {href: "?", className: "failingAlert bar"});
}
this.failedAlert.innerHTML = "Failing " + specPluralizedFor(this.failedCount);
if (this.failedCount === 1 && isDefined(dom.alert)) {
dom.alert.appendChild(this.failedAlert);
dom.alert.appendChild(this.resultsMenu);
}
// summary info
this.summaryMenuItem.innerHTML = "" + specPluralizedFor(this.runningSpecCount);
this.detailsMenuItem.innerHTML = "" + this.failedCount + " failing";
};
this.complete = function() {
dom.alert.removeChild(this.runningAlert);
this.skippedAlert.innerHTML = "Ran " + this.runningSpecCount + " of " + specPluralizedFor(this.totalSpecCount) + " - run all";
if (this.failedCount === 0) {
dom.alert.appendChild(this.createDom('span', {className: 'passingAlert bar'}, "Passing " + specPluralizedFor(this.passedCount)));
} else {
showDetails();
}
dom.banner.appendChild(this.createDom('span', {className: 'duration'}, "finished in " + ((new Date().getTime() - this.startedAt.getTime()) / 1000) + "s"));
};
return this;
function showDetails() {
if (dom.reporter.className.search(/showDetails/) === -1) {
dom.reporter.className += " showDetails";
}
}
function isUndefined(obj) {
return typeof obj === 'undefined';
}
function isDefined(obj) {
return !isUndefined(obj);
}
function specPluralizedFor(count) {
var str = count + " spec";
if (count > 1) {
str += "s"
}
return str;
}
};
jasmine.HtmlReporterHelpers.addHelpers(jasmine.HtmlReporter.ReporterView);
jasmine.HtmlReporter.SpecView = function(spec, dom, views) {
this.spec = spec;
this.dom = dom;
this.views = views;
this.symbol = this.createDom('li', { className: 'pending' });
this.dom.symbolSummary.appendChild(this.symbol);
this.summary = this.createDom('div', { className: 'specSummary' },
this.createDom('a', {
className: 'description',
href: jasmine.HtmlReporter.sectionLink(this.spec.getFullName()),
title: this.spec.getFullName()
}, this.spec.description)
);
this.detail = this.createDom('div', { className: 'specDetail' },
this.createDom('a', {
className: 'description',
href: '?spec=' + encodeURIComponent(this.spec.getFullName()),
title: this.spec.getFullName()
}, this.spec.getFullName())
);
};
jasmine.HtmlReporter.SpecView.prototype.status = function() {
return this.getSpecStatus(this.spec);
};
jasmine.HtmlReporter.SpecView.prototype.refresh = function() {
this.symbol.className = this.status();
switch (this.status()) {
case 'skipped':
break;
case 'passed':
this.appendSummaryToSuiteDiv();
break;
case 'failed':
this.appendSummaryToSuiteDiv();
this.appendFailureDetail();
break;
}
};
jasmine.HtmlReporter.SpecView.prototype.appendSummaryToSuiteDiv = function() {
this.summary.className += ' ' + this.status();
this.appendToSummary(this.spec, this.summary);
};
jasmine.HtmlReporter.SpecView.prototype.appendFailureDetail = function() {
this.detail.className += ' ' + this.status();
var resultItems = this.spec.results().getItems();
var messagesDiv = this.createDom('div', { className: 'messages' });
for (var i = 0; i < resultItems.length; i++) {
var result = resultItems[i];
if (result.type == 'log') {
messagesDiv.appendChild(this.createDom('div', {className: 'resultMessage log'}, result.toString()));
} else if (result.type == 'expect' && result.passed && !result.passed()) {
messagesDiv.appendChild(this.createDom('div', {className: 'resultMessage fail'}, result.message));
if (result.trace.stack) {
messagesDiv.appendChild(this.createDom('div', {className: 'stackTrace'}, result.trace.stack));
}
}
}
if (messagesDiv.childNodes.length > 0) {
this.detail.appendChild(messagesDiv);
this.dom.details.appendChild(this.detail);
}
};
jasmine.HtmlReporterHelpers.addHelpers(jasmine.HtmlReporter.SpecView);jasmine.HtmlReporter.SuiteView = function(suite, dom, views) {
this.suite = suite;
this.dom = dom;
this.views = views;
this.element = this.createDom('div', { className: 'suite' },
this.createDom('a', { className: 'description', href: jasmine.HtmlReporter.sectionLink(this.suite.getFullName()) }, this.suite.description)
);
this.appendToSummary(this.suite, this.element);
};
jasmine.HtmlReporter.SuiteView.prototype.status = function() {
return this.getSpecStatus(this.suite);
};
jasmine.HtmlReporter.SuiteView.prototype.refresh = function() {
this.element.className += " " + this.status();
};
jasmine.HtmlReporterHelpers.addHelpers(jasmine.HtmlReporter.SuiteView);
/* @deprecated Use jasmine.HtmlReporter instead
*/
jasmine.TrivialReporter = function(doc) {
this.document = doc || document;
this.suiteDivs = {};
this.logRunningSpecs = false;
};
jasmine.TrivialReporter.prototype.createDom = function(type, attrs, childrenVarArgs) {
var el = document.createElement(type);
for (var i = 2; i < arguments.length; i++) {
var child = arguments[i];
if (typeof child === 'string') {
el.appendChild(document.createTextNode(child));
} else {
if (child) { el.appendChild(child); }
}
}
for (var attr in attrs) {
if (attr == "className") {
el[attr] = attrs[attr];
} else {
el.setAttribute(attr, attrs[attr]);
}
}
return el;
};
jasmine.TrivialReporter.prototype.reportRunnerStarting = function(runner) {
var showPassed, showSkipped;
this.outerDiv = this.createDom('div', { id: 'TrivialReporter', className: 'jasmine_reporter' },
this.createDom('div', { className: 'banner' },
this.createDom('div', { className: 'logo' },
this.createDom('span', { className: 'title' }, "Jasmine"),
this.createDom('span', { className: 'version' }, runner.env.versionString())),
this.createDom('div', { className: 'options' },
"Show ",
showPassed = this.createDom('input', { id: "__jasmine_TrivialReporter_showPassed__", type: 'checkbox' }),
this.createDom('label', { "for": "__jasmine_TrivialReporter_showPassed__" }, " passed "),
showSkipped = this.createDom('input', { id: "__jasmine_TrivialReporter_showSkipped__", type: 'checkbox' }),
this.createDom('label', { "for": "__jasmine_TrivialReporter_showSkipped__" }, " skipped")
)
),
this.runnerDiv = this.createDom('div', { className: 'runner running' },
this.createDom('a', { className: 'run_spec', href: '?' }, "run all"),
this.runnerMessageSpan = this.createDom('span', {}, "Running..."),
this.finishedAtSpan = this.createDom('span', { className: 'finished-at' }, ""))
);
this.document.body.appendChild(this.outerDiv);
var suites = runner.suites();
for (var i = 0; i < suites.length; i++) {
var suite = suites[i];
var suiteDiv = this.createDom('div', { className: 'suite' },
this.createDom('a', { className: 'run_spec', href: '?spec=' + encodeURIComponent(suite.getFullName()) }, "run"),
this.createDom('a', { className: 'description', href: '?spec=' + encodeURIComponent(suite.getFullName()) }, suite.description));
this.suiteDivs[suite.id] = suiteDiv;
var parentDiv = this.outerDiv;
if (suite.parentSuite) {
parentDiv = this.suiteDivs[suite.parentSuite.id];
}
parentDiv.appendChild(suiteDiv);
}
this.startedAt = new Date();
var self = this;
showPassed.onclick = function(evt) {
if (showPassed.checked) {
self.outerDiv.className += ' show-passed';
} else {
self.outerDiv.className = self.outerDiv.className.replace(/ show-passed/, '');
}
};
showSkipped.onclick = function(evt) {
if (showSkipped.checked) {
self.outerDiv.className += ' show-skipped';
} else {
self.outerDiv.className = self.outerDiv.className.replace(/ show-skipped/, '');
}
};
};
jasmine.TrivialReporter.prototype.reportRunnerResults = function(runner) {
var results = runner.results();
var className = (results.failedCount > 0) ? "runner failed" : "runner passed";
this.runnerDiv.setAttribute("class", className);
//do it twice for IE
this.runnerDiv.setAttribute("className", className);
var specs = runner.specs();
var specCount = 0;
for (var i = 0; i < specs.length; i++) {
if (this.specFilter(specs[i])) {
specCount++;
}
}
var message = "" + specCount + " spec" + (specCount == 1 ? "" : "s" ) + ", " + results.failedCount + " failure" + ((results.failedCount == 1) ? "" : "s");
message += " in " + ((new Date().getTime() - this.startedAt.getTime()) / 1000) + "s";
this.runnerMessageSpan.replaceChild(this.createDom('a', { className: 'description', href: '?'}, message), this.runnerMessageSpan.firstChild);
this.finishedAtSpan.appendChild(document.createTextNode("Finished at " + new Date().toString()));
};
jasmine.TrivialReporter.prototype.reportSuiteResults = function(suite) {
var results = suite.results();
var status = results.passed() ? 'passed' : 'failed';
if (results.totalCount === 0) { // todo: change this to check results.skipped
status = 'skipped';
}
this.suiteDivs[suite.id].className += " " + status;
};
jasmine.TrivialReporter.prototype.reportSpecStarting = function(spec) {
if (this.logRunningSpecs) {
this.log('>> Jasmine Running ' + spec.suite.description + ' ' + spec.description + '...');
}
};
jasmine.TrivialReporter.prototype.reportSpecResults = function(spec) {
var results = spec.results();
var status = results.passed() ? 'passed' : 'failed';
if (results.skipped) {
status = 'skipped';
}
var specDiv = this.createDom('div', { className: 'spec ' + status },
this.createDom('a', { className: 'run_spec', href: '?spec=' + encodeURIComponent(spec.getFullName()) }, "run"),
this.createDom('a', {
className: 'description',
href: '?spec=' + encodeURIComponent(spec.getFullName()),
title: spec.getFullName()
}, spec.description));
var resultItems = results.getItems();
var messagesDiv = this.createDom('div', { className: 'messages' });
for (var i = 0; i < resultItems.length; i++) {
var result = resultItems[i];
if (result.type == 'log') {
messagesDiv.appendChild(this.createDom('div', {className: 'resultMessage log'}, result.toString()));
} else if (result.type == 'expect' && result.passed && !result.passed()) {
messagesDiv.appendChild(this.createDom('div', {className: 'resultMessage fail'}, result.message));
if (result.trace.stack) {
messagesDiv.appendChild(this.createDom('div', {className: 'stackTrace'}, result.trace.stack));
}
}
}
if (messagesDiv.childNodes.length > 0) {
specDiv.appendChild(messagesDiv);
}
this.suiteDivs[spec.suite.id].appendChild(specDiv);
};
jasmine.TrivialReporter.prototype.log = function() {
var console = jasmine.getGlobal().console;
if (console && console.log) {
if (console.log.apply) {
console.log.apply(console, arguments);
} else {
console.log(arguments); // ie fix: console.log.apply doesn't exist on ie
}
}
};
jasmine.TrivialReporter.prototype.getLocation = function() {
return this.document.location;
};
jasmine.TrivialReporter.prototype.specFilter = function(spec) {
var paramMap = {};
var params = this.getLocation().search.substring(1).split('&');
for (var i = 0; i < params.length; i++) {
var p = params[i].split('=');
paramMap[decodeURIComponent(p[0])] = decodeURIComponent(p[1]);
}
if (!paramMap.spec) {
return true;
}
return spec.getFullName().indexOf(paramMap.spec) === 0;
};

View File

@ -1,82 +0,0 @@
body { background-color: #eeeeee; padding: 0; margin: 5px; overflow-y: scroll; }
#HTMLReporter { font-size: 11px; font-family: Monaco, "Lucida Console", monospace; line-height: 14px; color: #333333; }
#HTMLReporter a { text-decoration: none; }
#HTMLReporter a:hover { text-decoration: underline; }
#HTMLReporter p, #HTMLReporter h1, #HTMLReporter h2, #HTMLReporter h3, #HTMLReporter h4, #HTMLReporter h5, #HTMLReporter h6 { margin: 0; line-height: 14px; }
#HTMLReporter .banner, #HTMLReporter .symbolSummary, #HTMLReporter .summary, #HTMLReporter .resultMessage, #HTMLReporter .specDetail .description, #HTMLReporter .alert .bar, #HTMLReporter .stackTrace { padding-left: 9px; padding-right: 9px; }
#HTMLReporter #jasmine_content { position: fixed; right: 100%; }
#HTMLReporter .version { color: #aaaaaa; }
#HTMLReporter .banner { margin-top: 14px; }
#HTMLReporter .duration { color: #aaaaaa; float: right; }
#HTMLReporter .symbolSummary { overflow: hidden; *zoom: 1; margin: 14px 0; }
#HTMLReporter .symbolSummary li { display: block; float: left; height: 7px; width: 14px; margin-bottom: 7px; font-size: 16px; }
#HTMLReporter .symbolSummary li.passed { font-size: 14px; }
#HTMLReporter .symbolSummary li.passed:before { color: #5e7d00; content: "\02022"; }
#HTMLReporter .symbolSummary li.failed { line-height: 9px; }
#HTMLReporter .symbolSummary li.failed:before { color: #b03911; content: "x"; font-weight: bold; margin-left: -1px; }
#HTMLReporter .symbolSummary li.skipped { font-size: 14px; }
#HTMLReporter .symbolSummary li.skipped:before { color: #bababa; content: "\02022"; }
#HTMLReporter .symbolSummary li.pending { line-height: 11px; }
#HTMLReporter .symbolSummary li.pending:before { color: #aaaaaa; content: "-"; }
#HTMLReporter .exceptions { color: #fff; float: right; margin-top: 5px; margin-right: 5px; }
#HTMLReporter .bar { line-height: 28px; font-size: 14px; display: block; color: #eee; }
#HTMLReporter .runningAlert { background-color: #666666; }
#HTMLReporter .skippedAlert { background-color: #aaaaaa; }
#HTMLReporter .skippedAlert:first-child { background-color: #333333; }
#HTMLReporter .skippedAlert:hover { text-decoration: none; color: white; text-decoration: underline; }
#HTMLReporter .passingAlert { background-color: #a6b779; }
#HTMLReporter .passingAlert:first-child { background-color: #5e7d00; }
#HTMLReporter .failingAlert { background-color: #cf867e; }
#HTMLReporter .failingAlert:first-child { background-color: #b03911; }
#HTMLReporter .results { margin-top: 14px; }
#HTMLReporter #details { display: none; }
#HTMLReporter .resultsMenu, #HTMLReporter .resultsMenu a { background-color: #fff; color: #333333; }
#HTMLReporter.showDetails .summaryMenuItem { font-weight: normal; text-decoration: inherit; }
#HTMLReporter.showDetails .summaryMenuItem:hover { text-decoration: underline; }
#HTMLReporter.showDetails .detailsMenuItem { font-weight: bold; text-decoration: underline; }
#HTMLReporter.showDetails .summary { display: none; }
#HTMLReporter.showDetails #details { display: block; }
#HTMLReporter .summaryMenuItem { font-weight: bold; text-decoration: underline; }
#HTMLReporter .summary { margin-top: 14px; }
#HTMLReporter .summary .suite .suite, #HTMLReporter .summary .specSummary { margin-left: 14px; }
#HTMLReporter .summary .specSummary.passed a { color: #5e7d00; }
#HTMLReporter .summary .specSummary.failed a { color: #b03911; }
#HTMLReporter .description + .suite { margin-top: 0; }
#HTMLReporter .suite { margin-top: 14px; }
#HTMLReporter .suite a { color: #333333; }
#HTMLReporter #details .specDetail { margin-bottom: 28px; }
#HTMLReporter #details .specDetail .description { display: block; color: white; background-color: #b03911; }
#HTMLReporter .resultMessage { padding-top: 14px; color: #333333; }
#HTMLReporter .resultMessage span.result { display: block; }
#HTMLReporter .stackTrace { margin: 5px 0 0 0; max-height: 224px; overflow: auto; line-height: 18px; color: #666666; border: 1px solid #ddd; background: white; white-space: pre; }
#TrivialReporter { padding: 8px 13px; position: absolute; top: 0; bottom: 0; left: 0; right: 0; overflow-y: scroll; background-color: white; font-family: "Helvetica Neue Light", "Lucida Grande", "Calibri", "Arial", sans-serif; /*.resultMessage {*/ /*white-space: pre;*/ /*}*/ }
#TrivialReporter a:visited, #TrivialReporter a { color: #303; }
#TrivialReporter a:hover, #TrivialReporter a:active { color: blue; }
#TrivialReporter .run_spec { float: right; padding-right: 5px; font-size: .8em; text-decoration: none; }
#TrivialReporter .banner { color: #303; background-color: #fef; padding: 5px; }
#TrivialReporter .logo { float: left; font-size: 1.1em; padding-left: 5px; }
#TrivialReporter .logo .version { font-size: .6em; padding-left: 1em; }
#TrivialReporter .runner.running { background-color: yellow; }
#TrivialReporter .options { text-align: right; font-size: .8em; }
#TrivialReporter .suite { border: 1px outset gray; margin: 5px 0; padding-left: 1em; }
#TrivialReporter .suite .suite { margin: 5px; }
#TrivialReporter .suite.passed { background-color: #dfd; }
#TrivialReporter .suite.failed { background-color: #fdd; }
#TrivialReporter .spec { margin: 5px; padding-left: 1em; clear: both; }
#TrivialReporter .spec.failed, #TrivialReporter .spec.passed, #TrivialReporter .spec.skipped { padding-bottom: 5px; border: 1px solid gray; }
#TrivialReporter .spec.failed { background-color: #fbb; border-color: red; }
#TrivialReporter .spec.passed { background-color: #bfb; border-color: green; }
#TrivialReporter .spec.skipped { background-color: #bbb; }
#TrivialReporter .messages { border-left: 1px dashed gray; padding-left: 1em; padding-right: 1em; }
#TrivialReporter .passed { background-color: #cfc; display: none; }
#TrivialReporter .failed { background-color: #fbb; }
#TrivialReporter .skipped { color: #777; background-color: #eee; display: none; }
#TrivialReporter .resultMessage span.result { display: block; line-height: 2em; color: black; }
#TrivialReporter .resultMessage .mismatch { color: black; }
#TrivialReporter .stackTrace { white-space: pre; font-size: .8em; margin-left: 10px; max-height: 5em; overflow: auto; border: 1px inset red; padding: 1em; background: #eef; }
#TrivialReporter .finished-at { padding-left: 1em; font-size: .6em; }
#TrivialReporter.show-passed .passed, #TrivialReporter.show-skipped .skipped { display: block; }
#TrivialReporter #jasmine_content { position: fixed; right: 100%; }
#TrivialReporter .runner { border: 1px solid gray; display: block; margin: 5px 0; padding: 2px 0 2px 10px; }

File diff suppressed because it is too large Load Diff

View File

@ -10,10 +10,12 @@ for (var i=0; i < libSources.length; i++) {
// list of files / patterns to load in the browser // list of files / patterns to load in the browser
files = [].concat([ files = [].concat([
JASMINE, MOCHA,
JASMINE_ADAPTER, MOCHA_ADAPTER,
"before.js", "before.js",
"karma.js" "karma.js",
"sinon.js",
"expect.js"
], libSources, [ ], libSources, [
"after.js", "after.js",
"happen.js", "happen.js",

231
spec/mocha/mocha.css Normal file
View File

@ -0,0 +1,231 @@
@charset "utf-8";
body {
font: 20px/1.5 "Helvetica Neue", Helvetica, Arial, sans-serif;
padding: 60px 50px;
}
#mocha ul, #mocha li {
margin: 0;
padding: 0;
}
#mocha ul {
list-style: none;
}
#mocha h1, #mocha h2 {
margin: 0;
}
#mocha h1 {
margin-top: 15px;
font-size: 1em;
font-weight: 200;
}
#mocha h1 a {
text-decoration: none;
color: inherit;
}
#mocha h1 a:hover {
text-decoration: underline;
}
#mocha .suite .suite h1 {
margin-top: 0;
font-size: .8em;
}
.hidden {
display: none;
}
#mocha h2 {
font-size: 12px;
font-weight: normal;
cursor: pointer;
}
#mocha .suite {
margin-left: 15px;
}
#mocha .test {
margin-left: 15px;
overflow: hidden;
}
#mocha .test.pending:hover h2::after {
content: '(pending)';
font-family: arial;
}
#mocha .test.pass.medium .duration {
background: #C09853;
}
#mocha .test.pass.slow .duration {
background: #B94A48;
}
#mocha .test.pass::before {
content: '✓';
font-size: 12px;
display: block;
float: left;
margin-right: 5px;
color: #00d6b2;
}
#mocha .test.pass .duration {
font-size: 9px;
margin-left: 5px;
padding: 2px 5px;
color: white;
-webkit-box-shadow: inset 0 1px 1px rgba(0,0,0,.2);
-moz-box-shadow: inset 0 1px 1px rgba(0,0,0,.2);
box-shadow: inset 0 1px 1px rgba(0,0,0,.2);
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
-ms-border-radius: 5px;
-o-border-radius: 5px;
border-radius: 5px;
}
#mocha .test.pass.fast .duration {
display: none;
}
#mocha .test.pending {
color: #0b97c4;
}
#mocha .test.pending::before {
content: '◦';
color: #0b97c4;
}
#mocha .test.fail {
color: #c00;
}
#mocha .test.fail pre {
color: black;
}
#mocha .test.fail::before {
content: '✖';
font-size: 12px;
display: block;
float: left;
margin-right: 5px;
color: #c00;
}
#mocha .test pre.error {
color: #c00;
max-height: 300px;
overflow: auto;
}
#mocha .test pre {
display: block;
float: left;
clear: left;
font: 12px/1.5 monaco, monospace;
margin: 5px;
padding: 15px;
border: 1px solid #eee;
border-bottom-color: #ddd;
-webkit-border-radius: 3px;
-webkit-box-shadow: 0 1px 3px #eee;
-moz-border-radius: 3px;
-moz-box-shadow: 0 1px 3px #eee;
}
#mocha .test h2 {
position: relative;
}
#mocha .test a.replay {
position: absolute;
top: 3px;
right: 0;
text-decoration: none;
vertical-align: middle;
display: block;
width: 15px;
height: 15px;
line-height: 15px;
text-align: center;
background: #eee;
font-size: 15px;
-moz-border-radius: 15px;
border-radius: 15px;
-webkit-transition: opacity 200ms;
-moz-transition: opacity 200ms;
transition: opacity 200ms;
opacity: 0.3;
color: #888;
}
#mocha .test:hover a.replay {
opacity: 1;
}
#mocha-report.pass .test.fail {
display: none;
}
#mocha-report.fail .test.pass {
display: none;
}
#mocha-error {
color: #c00;
font-size: 1.5 em;
font-weight: 100;
letter-spacing: 1px;
}
#mocha-stats {
position: fixed;
top: 15px;
right: 10px;
font-size: 12px;
margin: 0;
color: #888;
}
#mocha-stats .progress {
float: right;
padding-top: 0;
}
#mocha-stats em {
color: black;
}
#mocha-stats a {
text-decoration: none;
color: inherit;
}
#mocha-stats a:hover {
border-bottom: 1px solid #eee;
}
#mocha-stats li {
display: inline-block;
margin: 0 5px;
list-style: none;
padding-top: 11px;
}
code .comment { color: #ddd }
code .init { color: #2F6FAD }
code .string { color: #5890AD }
code .keyword { color: #8A6343 }
code .number { color: #2F6FAD }

5340
spec/mocha/mocha.js Normal file

File diff suppressed because it is too large Load Diff

4223
spec/sinon.js Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,12 +1,12 @@
describe('L#noConflict', function() { describe('L#noConflict', function() {
it('restores the previous L value and returns Leaflet namespace', function(){ it('restores the previous L value and returns Leaflet namespace', function(){
expect(L.version).toBeDefined(); expect(L.version).to.be.ok();
var L2 = L.noConflict(); var L2 = L.noConflict();
expect(L).toEqual('test'); expect(L).to.eql('test');
expect(L2.version).toBeDefined(); expect(L2.version).to.be.ok();
window.L = L2; window.L = L2;
}); });

View File

@ -11,25 +11,25 @@ describe("Control.Attribution", function () {
}); });
it("contains just prefix if no attributions added", function () { it("contains just prefix if no attributions added", function () {
expect(container.innerHTML).toEqual('prefix'); expect(container.innerHTML).to.eql('prefix');
}); });
describe('#addAttribution', function () { describe('#addAttribution', function () {
it('adds one attribution correctly', function () { it('adds one attribution correctly', function () {
control.addAttribution('foo'); control.addAttribution('foo');
expect(container.innerHTML).toEqual('prefix | foo'); expect(container.innerHTML).to.eql('prefix | foo');
}); });
it('adds no duplicate attributions', function () { it('adds no duplicate attributions', function () {
control.addAttribution('foo'); control.addAttribution('foo');
control.addAttribution('foo'); control.addAttribution('foo');
expect(container.innerHTML).toEqual('prefix | foo'); expect(container.innerHTML).to.eql('prefix | foo');
}); });
it('adds several attributions listed with comma', function () { it('adds several attributions listed with comma', function () {
control.addAttribution('foo'); control.addAttribution('foo');
control.addAttribution('bar'); control.addAttribution('bar');
expect(container.innerHTML).toEqual('prefix | foo, bar'); expect(container.innerHTML).to.eql('prefix | foo, bar');
}); });
}); });
@ -38,7 +38,7 @@ describe("Control.Attribution", function () {
control.addAttribution('foo'); control.addAttribution('foo');
control.addAttribution('bar'); control.addAttribution('bar');
control.removeAttribution('foo'); control.removeAttribution('foo');
expect(container.innerHTML).toEqual('prefix | bar'); expect(container.innerHTML).to.eql('prefix | bar');
}); });
it('does nothing if removing attribution that was not present', function () { it('does nothing if removing attribution that was not present', function () {
control.addAttribution('foo'); control.addAttribution('foo');
@ -47,21 +47,21 @@ describe("Control.Attribution", function () {
control.removeAttribution('baz'); control.removeAttribution('baz');
control.removeAttribution('baz'); control.removeAttribution('baz');
control.removeAttribution(''); control.removeAttribution('');
expect(container.innerHTML).toEqual('prefix | foo'); expect(container.innerHTML).to.eql('prefix | foo');
}); });
}); });
describe('#setPrefix', function () { describe('#setPrefix', function () {
it('changes prefix', function () { it('changes prefix', function () {
control.setPrefix('bla'); control.setPrefix('bla');
expect(container.innerHTML).toEqual('bla'); expect(container.innerHTML).to.eql('bla');
}); });
}); });
describe('control.attribution factory', function () { describe('control.attribution factory', function () {
it('creates Control.Attribution instance', function () { it('creates Control.Attribution instance', function () {
var options = {prefix: 'prefix'}; var options = {prefix: 'prefix'};
expect(L.control.attribution(options)).toEqual(new L.Control.Attribution(options)); expect(L.control.attribution(options)).to.eql(new L.Control.Attribution(options));
}); });
}); });

View File

@ -9,26 +9,26 @@ describe("Control.Layers", function () {
it("is fired on input that changes the base layer", function () { it("is fired on input that changes the base layer", function () {
var baseLayers = {"Layer 1": L.tileLayer(), "Layer 2": L.tileLayer()}, var baseLayers = {"Layer 1": L.tileLayer(), "Layer 2": L.tileLayer()},
layers = L.control.layers(baseLayers).addTo(map), layers = L.control.layers(baseLayers).addTo(map),
spy = jasmine.createSpy(); spy = sinon.spy();
map.on('baselayerchange', spy) map.on('baselayerchange', spy)
.whenReady(function(){ .whenReady(function() {
happen.click(layers._baseLayersList.getElementsByTagName("input")[0]); happen.click(layers._baseLayersList.getElementsByTagName("input")[0]);
expect(spy).toHaveBeenCalled(); expect(spy.called).to.be.ok();
expect(spy.mostRecentCall.args[0].layer).toBe(baseLayers["Layer 1"]); expect(spy.mostRecentCall.args[0].layer).to.be(baseLayers["Layer 1"]);
}); });
}); });
it("is not fired on input that doesn't change the base layer", function () { it("is not fired on input that doesn't change the base layer", function () {
var overlays = {"Marker 1": L.marker([0, 0]), "Marker 2": L.marker([0, 0])}, var overlays = {"Marker 1": L.marker([0, 0]), "Marker 2": L.marker([0, 0])},
layers = L.control.layers({}, overlays).addTo(map), layers = L.control.layers({}, overlays).addTo(map),
spy = jasmine.createSpy(); spy = sinon.spy();
map.on('baselayerchange', spy); map.on('baselayerchange', spy);
happen.click(layers._overlaysList.getElementsByTagName("input")[0]); happen.click(layers._overlaysList.getElementsByTagName("input")[0]);
expect(spy).not.toHaveBeenCalled(); expect(spy.called).to.not.be.ok();
}); });
}); });
@ -42,13 +42,13 @@ describe("Control.Layers", function () {
overlay = L.marker([0, 0]), overlay = L.marker([0, 0]),
layers = L.control.layers({"Base": baseLayer}, {"Overlay": overlay}).addTo(map); layers = L.control.layers({"Base": baseLayer}, {"Overlay": overlay}).addTo(map);
spyOn(layers, '_update').andCallThrough(); var spy = sinon.spy(layers, '_update');
map.addLayer(overlay); map.addLayer(overlay);
map.removeLayer(overlay); map.removeLayer(overlay);
expect(layers._update).toHaveBeenCalled(); expect(spy.called).to.be.ok();
expect(layers._update.callCount).toEqual(2); expect(spy.callCount).to.eql(2);
}); });
it("not when a non-included layer is added or removed", function () { it("not when a non-included layer is added or removed", function () {
@ -56,12 +56,12 @@ describe("Control.Layers", function () {
overlay = L.marker([0, 0]), overlay = L.marker([0, 0]),
layers = L.control.layers({"Base": baseLayer}).addTo(map); layers = L.control.layers({"Base": baseLayer}).addTo(map);
spyOn(layers, '_update').andCallThrough(); var spy = sinon.spy(layers, '_update');
map.addLayer(overlay); map.addLayer(overlay);
map.removeLayer(overlay); map.removeLayer(overlay);
expect(layers._update).not.toHaveBeenCalled(); expect(spy.called).to.not.be.ok();
}); });
}); });
}); });

View File

@ -6,8 +6,8 @@ describe("Class", function() {
method; method;
beforeEach(function() { beforeEach(function() {
constructor = jasmine.createSpy("Klass constructor"); constructor = sinon.spy();
method = jasmine.createSpy("Klass#bar method"); method = sinon.spy();
Klass = L.Class.extend({ Klass = L.Class.extend({
statics: {bla: 1}, statics: {bla: 1},
@ -22,12 +22,12 @@ describe("Class", function() {
it("creates a class with the given constructor & properties", function() { it("creates a class with the given constructor & properties", function() {
var a = new Klass(); var a = new Klass();
expect(constructor).toHaveBeenCalled(); expect(constructor.called).to.be.ok();
expect(a.foo).toEqual(5); expect(a.foo).to.eql(5);
a.bar(); a.bar();
expect(method).toHaveBeenCalled(); expect(method.called).to.be.ok();
}); });
it("inherits parent classes' constructor & properties", function() { it("inherits parent classes' constructor & properties", function() {
@ -35,36 +35,36 @@ describe("Class", function() {
var b = new Klass2(); var b = new Klass2();
expect(b instanceof Klass).toBeTruthy(); expect(b instanceof Klass).to.be.ok();
expect(b instanceof Klass2).toBeTruthy(); expect(b instanceof Klass2).to.be.ok();
expect(constructor).toHaveBeenCalled(); expect(constructor.called).to.be.ok();
expect(b.baz).toEqual(2); expect(b.baz).to.eql(2);
b.bar(); b.bar();
expect(method).toHaveBeenCalled(); expect(method.called).to.be.ok();
}); });
it("supports static properties", function() { it("supports static properties", function() {
expect(Klass.bla).toEqual(1); expect(Klass.bla).to.eql(1);
}); });
it("inherits parent static properties", function() { it("inherits parent static properties", function() {
var Klass2 = Klass.extend({}); var Klass2 = Klass.extend({});
expect(Klass2.bla).toEqual(1); expect(Klass2.bla).to.eql(1);
}); });
it("overrides parent static properties", function() { it("overrides parent static properties", function() {
var Klass2 = Klass.extend({statics: {bla: 2}}); var Klass2 = Klass.extend({statics: {bla: 2}});
expect(Klass2.bla).toEqual(2); expect(Klass2.bla).to.eql(2);
}); });
it("includes the given mixin", function() { it("includes the given mixin", function() {
var a = new Klass(); var a = new Klass();
expect(a.mixin).toBeTruthy(); expect(a.mixin).to.be.ok();
}); });
it("includes multiple mixins", function() { it("includes multiple mixins", function() {
@ -73,15 +73,15 @@ describe("Class", function() {
}); });
var a = new Klass2(); var a = new Klass2();
expect(a.mixin).toBeTruthy(); expect(a.mixin).to.be.ok();
expect(a.mixin2).toBeTruthy(); expect(a.mixin2).to.be.ok();
}); });
it("grants the ability to include the given mixin", function() { it("grants the ability to include the given mixin", function() {
Klass.include({mixin2: true}); Klass.include({mixin2: true});
var a = new Klass(); var a = new Klass();
expect(a.mixin2).toBeTruthy(); expect(a.mixin2).to.be.ok();
}); });
it("merges options instead of replacing them", function() { it("merges options instead of replacing them", function() {
@ -100,7 +100,7 @@ describe("Class", function() {
var a = new KlassWithOptions2(); var a = new KlassWithOptions2();
expect(a.options).toEqual({ expect(a.options).to.eql({
foo1: 1, foo1: 1,
foo2: 3, foo2: 3,
foo3: 4 foo3: 4
@ -108,20 +108,20 @@ describe("Class", function() {
}); });
it("adds constructor hooks correctly", function () { it("adds constructor hooks correctly", function () {
var spy1 = jasmine.createSpy("init hook 1"); var spy1 = sinon.spy();
Klass.addInitHook(spy1); Klass.addInitHook(spy1);
Klass.addInitHook('bar', 1, 2, 3); Klass.addInitHook('bar', 1, 2, 3);
var a = new Klass(); var a = new Klass();
expect(spy1).toHaveBeenCalled(); expect(spy1.called).to.be.ok();
expect(method).toHaveBeenCalledWith(1, 2, 3); expect(method.calledWith(1, 2, 3));
}); });
it("inherits constructor hooks", function () { it("inherits constructor hooks", function () {
var spy1 = jasmine.createSpy("init hook 1"), var spy1 = sinon.spy(),
spy2 = jasmine.createSpy("init hook 2"); spy2 = sinon.spy();
var Klass2 = Klass.extend({}); var Klass2 = Klass.extend({});
@ -130,13 +130,13 @@ describe("Class", function() {
var a = new Klass2(); var a = new Klass2();
expect(spy1).toHaveBeenCalled(); expect(spy1.called).to.be.ok();
expect(spy2).toHaveBeenCalled(); expect(spy2.called).to.be.ok();
}); });
it("does not call child constructor hooks", function () { it("does not call child constructor hooks", function () {
var spy1 = jasmine.createSpy("init hook 1"), var spy1 = sinon.spy(),
spy2 = jasmine.createSpy("init hook 2"); spy2 = sinon.spy();
var Klass2 = Klass.extend({}); var Klass2 = Klass.extend({});
@ -145,8 +145,8 @@ describe("Class", function() {
var a = new Klass(); var a = new Klass();
expect(spy1).toHaveBeenCalled(); expect(spy1.called).to.be.ok();
expect(spy2).not.toHaveBeenCalled(); expect(spy2.called).to.eql(false);
}); });
}); });

View File

@ -11,35 +11,35 @@ describe('Events', function() {
it('fires all listeners added through #addEventListener', function() { it('fires all listeners added through #addEventListener', function() {
var obj = new Klass(), var obj = new Klass(),
spy = jasmine.createSpy(), spy1 = sinon.spy(),
spy2 = jasmine.createSpy(), spy2 = sinon.spy(),
spy3 = jasmine.createSpy(), spy3 = sinon.spy(),
spy4 = jasmine.createSpy(), spy4 = sinon.spy(),
spy5 = jasmine.createSpy(); spy5 = sinon.spy();
spy6 = jasmine.createSpy(); spy6 = sinon.spy();
obj.addEventListener('test', spy); obj.addEventListener('test', spy1);
obj.addEventListener('test', spy2); obj.addEventListener('test', spy2);
obj.addEventListener('other', spy3); obj.addEventListener('other', spy3);
obj.addEventListener({ test: spy4, other: spy5 }); obj.addEventListener({ test: spy4, other: spy5 });
obj.addEventListener({'test other': spy6 }); obj.addEventListener({'test other': spy6 });
expect(spy).not.toHaveBeenCalled(); expect(spy1.called).to.be(false);
expect(spy2).not.toHaveBeenCalled(); expect(spy2.called).to.be(false);
expect(spy3).not.toHaveBeenCalled(); expect(spy3.called).to.be(false);
expect(spy4).not.toHaveBeenCalled(); expect(spy4.called).to.be(false);
expect(spy5).not.toHaveBeenCalled(); expect(spy5.called).to.be(false);
expect(spy6).not.toHaveBeenCalled(); expect(spy6.called).to.be(false);
obj.fireEvent('test'); obj.fireEvent('test');
expect(spy).toHaveBeenCalled(); expect(spy1.called).to.be(true);
expect(spy2).toHaveBeenCalled(); expect(spy2.called).to.be(true);
expect(spy3).not.toHaveBeenCalled(); expect(spy3.called).to.be(false);
expect(spy4).toHaveBeenCalled(); expect(spy4.called).to.be(true);
expect(spy5).not.toHaveBeenCalled(); expect(spy5.called).to.be(false);
expect(spy6).toHaveBeenCalled(); expect(spy6.called).to.be(true);
expect(spy6.calls.length).toEqual(1); expect(spy6.callCount).to.be(1);
}); });
it('provides event object to listeners and executes them in the right context', function() { it('provides event object to listeners and executes them in the right context', function() {
@ -50,31 +50,31 @@ describe('Events', function() {
foo = {}; foo = {};
function listener1(e) { function listener1(e) {
expect(e.type).toEqual('test'); expect(e.type).to.eql('test');
expect(e.target).toEqual(obj); expect(e.target).to.eql(obj);
expect(this).toEqual(obj); expect(this).to.eql(obj);
expect(e.baz).toEqual(1); expect(e.baz).to.eql(1);
} }
function listener2(e) { function listener2(e) {
expect(e.type).toEqual('test'); expect(e.type).to.eql('test');
expect(e.target).toEqual(obj2); expect(e.target).to.eql(obj2);
expect(this).toEqual(foo); expect(this).to.eql(foo);
expect(e.baz).toEqual(2); expect(e.baz).to.eql(2);
} }
function listener3(e) { function listener3(e) {
expect(e.type).toEqual('test'); expect(e.type).to.eql('test');
expect(e.target).toEqual(obj3); expect(e.target).to.eql(obj3);
expect(this).toEqual(obj3); expect(this).to.eql(obj3);
expect(e.baz).toEqual(3); expect(e.baz).to.eql(3);
} }
function listener4(e) { function listener4(e) {
expect(e.type).toEqual('test'); expect(e.type).to.eql('test');
expect(e.target).toEqual(obj4); expect(e.target).to.eql(obj4);
expect(this).toEqual(foo); expect(this).to.eql(foo);
expect(e.baz).toEqual(4); expect(e.baz).to.eql(4);
} }
obj.addEventListener('test', listener1); obj.addEventListener('test', listener1);
@ -90,18 +90,18 @@ describe('Events', function() {
it('calls no listeners removed through #removeEventListener', function() { it('calls no listeners removed through #removeEventListener', function() {
var obj = new Klass(), var obj = new Klass(),
spy = jasmine.createSpy(), spy = sinon.spy(),
spy2 = jasmine.createSpy(), spy2 = sinon.spy(),
spy3 = jasmine.createSpy(), spy3 = sinon.spy(),
spy4 = jasmine.createSpy(), spy4 = sinon.spy(),
spy5 = jasmine.createSpy(); spy5 = sinon.spy();
obj.addEventListener('test', spy); obj.addEventListener('test', spy);
obj.removeEventListener('test', spy); obj.removeEventListener('test', spy);
obj.fireEvent('test'); obj.fireEvent('test');
expect(spy).not.toHaveBeenCalled(); expect(spy.called).to.be(false);
obj.addEventListener('test2', spy2); obj.addEventListener('test2', spy2);
obj.addEventListener('test2', spy3); obj.addEventListener('test2', spy3);
@ -109,8 +109,8 @@ describe('Events', function() {
obj.fireEvent('test2'); obj.fireEvent('test2');
expect(spy2).not.toHaveBeenCalled(); expect(spy2.called).to.be(false);
expect(spy3).not.toHaveBeenCalled(); expect(spy3.called).to.be(false);
obj.addEventListener('test3', spy4); obj.addEventListener('test3', spy4);
obj.addEventListener('test4', spy5); obj.addEventListener('test4', spy5);
@ -122,45 +122,45 @@ describe('Events', function() {
obj.fireEvent('test3'); obj.fireEvent('test3');
obj.fireEvent('test4'); obj.fireEvent('test4');
expect(spy4).not.toHaveBeenCalled(); expect(spy4.called).to.be(false);
expect(spy5).not.toHaveBeenCalled(); expect(spy5.called).to.be(false);
}); });
// added due to context-sensitive removeListener optimization // added due to context-sensitive removeListener optimization
it('fires multiple listeners with the same context with id', function () { it('fires multiple listeners with the same context with id', function () {
var obj = new Klass(), var obj = new Klass(),
spy = jasmine.createSpy(), spy1 = sinon.spy(),
spy2 = jasmine.createSpy(), spy2 = sinon.spy(),
foo = {}; foo = {};
L.Util.stamp(foo); L.Util.stamp(foo);
obj.addEventListener('test', spy, foo); obj.addEventListener('test', spy1, foo);
obj.addEventListener('test', spy2, foo); obj.addEventListener('test', spy2, foo);
obj.fireEvent('test'); obj.fireEvent('test');
expect(spy).toHaveBeenCalled(); expect(spy1.called).to.be(true);
expect(spy2).toHaveBeenCalled(); expect(spy2.called).to.be(true);
}); });
it('removes listeners with stamped contexts', function () { it('removes listeners with stamped contexts', function () {
var obj = new Klass(), var obj = new Klass(),
spy = jasmine.createSpy(), spy1 = sinon.spy(),
spy2 = jasmine.createSpy(), spy2 = sinon.spy(),
foo = {}; foo = {};
L.Util.stamp(foo); L.Util.stamp(foo);
obj.addEventListener('test', spy, foo); obj.addEventListener('test', spy1, foo);
obj.addEventListener('test', spy2, foo); obj.addEventListener('test', spy2, foo);
obj.removeEventListener('test', spy, foo); obj.removeEventListener('test', spy1, foo);
obj.fireEvent('test'); obj.fireEvent('test');
expect(spy).not.toHaveBeenCalled(); expect(spy1.called).to.be(false);
expect(spy2).toHaveBeenCalled(); expect(spy2.called).to.be(true);
}); });
it('removes listeners with a stamp originally added without one', function() { it('removes listeners with a stamp originally added without one', function() {
@ -208,23 +208,23 @@ describe('Events', function() {
it('works like #addEventListener && #removeEventListener', function() { it('works like #addEventListener && #removeEventListener', function() {
var obj = new Klass(), var obj = new Klass(),
spy = jasmine.createSpy(); spy = sinon.spy();
obj.on('test', spy); obj.on('test', spy);
obj.fire('test'); obj.fire('test');
expect(spy).toHaveBeenCalled(); expect(spy.called).to.be(true);
obj.off('test', spy); obj.off('test', spy);
obj.fireEvent('test'); obj.fireEvent('test');
expect(spy.callCount).toBeLessThan(2); expect(spy.callCount).to.be.lessThan(2);
}); });
it('does not override existing methods with the same name', function() { it('does not override existing methods with the same name', function() {
var spy1 = jasmine.createSpy(), var spy1 = sinon.spy(),
spy2 = jasmine.createSpy(), spy2 = sinon.spy(),
spy3 = jasmine.createSpy(); spy3 = sinon.spy();
var Klass2 = L.Class.extend({ var Klass2 = L.Class.extend({
includes: L.Mixin.Events, includes: L.Mixin.Events,
@ -236,13 +236,13 @@ describe('Events', function() {
var obj = new Klass2(); var obj = new Klass2();
obj.on(); obj.on();
expect(spy1).toHaveBeenCalled(); expect(spy1.called).to.be(true);
obj.off(); obj.off();
expect(spy2).toHaveBeenCalled(); expect(spy2.called).to.be(true);
obj.fire(); obj.fire();
expect(spy3).toHaveBeenCalled(); expect(spy3.called).to.be(true);
}); });
}); });
}); });

View File

@ -16,7 +16,7 @@ describe('Util', function() {
baz: 3 baz: 3
}); });
expect(a).toEqual({ expect(a).to.eql({
foo: 5, foo: 5,
bar: 7, bar: 7,
baz: 3 baz: 3
@ -26,7 +26,7 @@ describe('Util', function() {
it('accepts more than 2 arguments', function() { it('accepts more than 2 arguments', function() {
L.Util.extend(a, {bar: 7}, {baz: 3}); L.Util.extend(a, {bar: 7}, {baz: 3});
expect(a).toEqual({ expect(a).to.eql({
foo: 5, foo: 5,
bar: 7, bar: 7,
baz: 3 baz: 3
@ -40,13 +40,13 @@ describe('Util', function() {
return this; return this;
}; };
var fn2 = L.Util.bind(fn, 5); var fn2 = L.Util.bind(fn, { foo: 'bar' });
expect(fn2()).toEqual(5); expect(fn2()).to.eql({ foo: 'bar' });
}); });
it('passes additional arguments to the bound function', function () { it('passes additional arguments to the bound function', function () {
var fn = jasmine.createSpy(), var fn = sinon.spy(),
foo = {}, foo = {},
a = {}, a = {},
b = {}; b = {};
@ -55,7 +55,7 @@ describe('Util', function() {
fn2(); fn2();
expect(fn).toHaveBeenCalledWith(a, b); expect(fn.calledWith(a, b)).to.be.ok();
}); });
}); });
@ -64,26 +64,26 @@ describe('Util', function() {
var a = {}, var a = {},
id = L.Util.stamp(a); id = L.Util.stamp(a);
expect(typeof id).toEqual('number'); expect(typeof id).to.eql('number');
expect(L.Util.stamp(a)).toEqual(id); expect(L.Util.stamp(a)).to.eql(id);
var b = {}, var b = {},
id2 = L.Util.stamp(b); id2 = L.Util.stamp(b);
expect(id2).not.toEqual(id); expect(id2).not.to.eql(id);
}); });
}); });
describe('#falseFn', function () { describe('#falseFn', function () {
it('returns false', function () { it('returns false', function () {
expect(L.Util.falseFn()).toBe(false); expect(L.Util.falseFn()).to.be(false);
}); });
}); });
describe('#formatNum', function () { describe('#formatNum', function () {
it('formats numbers with a given precision', function () { it('formats numbers with a given precision', function () {
expect(L.Util.formatNum(13.12325555, 3)).toEqual(13.123); expect(L.Util.formatNum(13.12325555, 3)).to.eql(13.123);
expect(L.Util.formatNum(13.12325555)).toEqual(13.12326); expect(L.Util.formatNum(13.12325555)).to.eql(13.12326);
}); });
}); });
@ -96,7 +96,7 @@ describe('Util', function() {
result: "?bar=7&baz=3" result: "?bar=7&baz=3"
}; };
expect(L.Util.getParamString(a.obj,a.url)).toEqual(a.result); expect(L.Util.getParamString(a.obj,a.url)).to.eql(a.result);
var b = { var b = {
url: "http://example.com/get?justone=qs", url: "http://example.com/get?justone=qs",
@ -104,7 +104,7 @@ describe('Util', function() {
result: "&bar=7&baz=3" result: "&bar=7&baz=3"
}; };
expect(L.Util.getParamString(b.obj,b.url)).toEqual(b.result); expect(L.Util.getParamString(b.obj,b.url)).to.eql(b.result);
var c = { var c = {
url: undefined, url: undefined,
@ -112,72 +112,49 @@ describe('Util', function() {
result: "?bar=7&baz=3" result: "?bar=7&baz=3"
}; };
expect(L.Util.getParamString(c.obj,c.url)).toEqual(c.result); expect(L.Util.getParamString(c.obj,c.url)).to.eql(c.result);
}); });
}); });
describe('#requestAnimFrame', function () { describe('#requestAnimFrame', function () {
it('calles a function on next frame, unless canceled', function () { it('calles a function on next frame, unless canceled', function (done) {
var spy = jasmine.createSpy(), var spy = sinon.spy(),
spy2 = jasmine.createSpy(), spy2 = sinon.spy(),
called = false,
foo = {}; foo = {};
runs(function () { L.Util.requestAnimFrame(spy);
L.Util.requestAnimFrame(spy);
L.Util.requestAnimFrame(function () { L.Util.requestAnimFrame(function () {
called = true; expect(this).to.eql(foo);
expect(this).toEqual(foo); done();
spy(); }, foo);
}, foo);
L.Util.cancelAnimFrame(spy); L.Util.cancelAnimFrame(spy);
});
waitsFor(function () {
return called;
}, 'function should be called', 500);
runs(function () {
expect(spy).toHaveBeenCalled();
expect(spy2).not.toHaveBeenCalled();
});
}); });
}); });
describe('#limitExecByInterval', function() { describe('#limitExecByInterval', function() {
it('limits execution to not more often than specified time interval', function () { it('limits execution to not more often than specified time interval', function (done) {
var spy = jasmine.createSpy(), var spy = sinon.spy();
check = false;
var fn = L.Util.limitExecByInterval(spy, 20); var fn = L.Util.limitExecByInterval(spy, 20);
runs(function () { fn();
fn(); fn();
fn(); fn();
fn();
expect(spy.calls.length).toEqual(1); expect(spy.callCount).to.eql(1);
setTimeout(function () { setTimeout(function () {
check = true; expect(spy.callCount).to.eql(2);
}, 30); done();
}); }, 30);
waitsFor(function () {
return check;
});
runs(function () {
expect(spy.calls.length).toEqual(2);
});
}); });
}); });
describe('#splitWords', function () { describe('#splitWords', function () {
it('splits words into an array', function () { it('splits words into an array', function () {
expect(L.Util.splitWords('foo bar baz')).toEqual(['foo', 'bar', 'baz']); expect(L.Util.splitWords('foo bar baz')).to.eql(['foo', 'bar', 'baz']);
}); });
}); });
@ -192,17 +169,17 @@ describe('Util', function() {
bar: 'Dave' bar: 'Dave'
}); });
expect(str).toEqual('Hello Vlad and Dave!'); expect(str).to.eql('Hello Vlad and Dave!');
}); });
it('does not modify text without a token variable', function () { it('does not modify text without a token variable', function () {
expect(L.Util.template('foo', {})).toEqual('foo'); expect(L.Util.template('foo', {})).to.eql('foo');
}); });
it('throws when a template token is not given', function () { it('throws when a template token is not given', function () {
expect(function () { expect(function () {
L.Util.template(tpl, {foo: 'bar'}); L.Util.template(tpl, {foo: 'bar'});
}).toThrow(); }).to.throwError();
}); });
}); });
}); });

View File

@ -11,84 +11,84 @@ describe('DomEvent', function() {
return el.fireEvent('onclick'); return el.fireEvent('onclick');
} }
} }
beforeEach(function() { beforeEach(function() {
el = document.createElement('div'); el = document.createElement('div');
el.style.position = 'absolute'; el.style.position = 'absolute';
el.style.top = el.style.left = '-10000px'; el.style.top = el.style.left = '-10000px';
document.body.appendChild(el); document.body.appendChild(el);
}); });
afterEach(function() { afterEach(function() {
document.body.removeChild(el); document.body.removeChild(el);
}); });
describe('#addListener', function() { describe('#addListener', function() {
it('adds a listener and calls it on event', function() { it('adds a listener and calls it on event', function() {
var listener1 = jasmine.createSpy('listener1'), var listener1 = sinon.spy(),
listener2 = jasmine.createSpy('listener2'); listener2 = sinon.spy();
L.DomEvent.addListener(el, 'click', listener1); L.DomEvent.addListener(el, 'click', listener1);
L.DomEvent.addListener(el, 'click', listener2); L.DomEvent.addListener(el, 'click', listener2);
simulateClick(el); simulateClick(el);
expect(listener1).toHaveBeenCalled(); expect(listener1.called).to.be.ok();
expect(listener2).toHaveBeenCalled(); expect(listener2.called).to.be.ok();
}); });
it('binds "this" to the given context', function() { it('binds "this" to the given context', function() {
var obj = {foo: 'bar'}, var obj = {foo: 'bar'},
result; result;
L.DomEvent.addListener(el, 'click', function() { L.DomEvent.addListener(el, 'click', function() {
result = this; result = this;
}, obj); }, obj);
simulateClick(el); simulateClick(el);
expect(result).toEqual(obj); expect(result).to.eql(obj);
}); });
it('passes an event object to the listener', function() { it('passes an event object to the listener', function() {
var type; var type;
L.DomEvent.addListener(el, 'click', function(e) { L.DomEvent.addListener(el, 'click', function(e) {
type = e && e.type; type = e && e.type;
}); });
simulateClick(el); simulateClick(el);
expect(type).toEqual('click'); expect(type).to.eql('click');
}); });
}); });
describe('#removeListener', function() { describe('#removeListener', function() {
it('removes a previously added listener', function() { it('removes a previously added listener', function() {
var listener = jasmine.createSpy('listener'); var listener = sinon.spy();
L.DomEvent.addListener(el, 'click', listener); L.DomEvent.addListener(el, 'click', listener);
L.DomEvent.removeListener(el, 'click', listener); L.DomEvent.removeListener(el, 'click', listener);
simulateClick(el); simulateClick(el);
expect(listener).not.toHaveBeenCalled(); expect(listener.called).to.not.be.ok();
}); });
}); });
describe('#stopPropagation', function() { describe('#stopPropagation', function() {
it('stops propagation of the given event', function() { it('stops propagation of the given event', function() {
var child = document.createElement('div'), var child = document.createElement('div'),
listener = jasmine.createSpy('listener'); listener = sinon.spy();
el.appendChild(child); el.appendChild(child);
L.DomEvent.addListener(child, 'click', L.DomEvent.stopPropagation); L.DomEvent.addListener(child, 'click', L.DomEvent.stopPropagation);
L.DomEvent.addListener(el, 'click', listener); L.DomEvent.addListener(el, 'click', listener);
simulateClick(child); simulateClick(child);
expect(listener).not.toHaveBeenCalled(); expect(listener.called).to.not.be.ok();
el.removeChild(child); el.removeChild(child);
}); });
}); });
@ -96,7 +96,7 @@ describe('DomEvent', function() {
it('prevents the default action of event', function() { it('prevents the default action of event', function() {
L.DomEvent.addListener(el, 'click', L.DomEvent.preventDefault); L.DomEvent.addListener(el, 'click', L.DomEvent.preventDefault);
expect(simulateClick(el)).toBe(false); expect(simulateClick(el)).to.be(false);
}); });
}); });
}); });

View File

@ -15,48 +15,48 @@ describe('DomUtil', function() {
describe('#get', function() { describe('#get', function() {
it('gets element by id if the given argument is string', function() { it('gets element by id if the given argument is string', function() {
el.id = 'testId'; el.id = 'testId';
expect(L.DomUtil.get(el.id)).toBe(el); expect(L.DomUtil.get(el.id)).to.eql(el);
}); });
it('returns the element if it is given as an argument', function() { it('returns the element if it is given as an argument', function() {
expect(L.DomUtil.get(el)).toBe(el); expect(L.DomUtil.get(el)).to.eql(el);
}); });
}); });
describe('#addClass, #removeClass, #hasClass', function() { describe('#addClass, #removeClass, #hasClass', function() {
it('has defined class for test element', function() { it('has defined class for test element', function() {
el.className = 'bar foo baz '; el.className = 'bar foo baz ';
expect(L.DomUtil.hasClass(el, 'foo')).toBeTruthy(); expect(L.DomUtil.hasClass(el, 'foo')).to.be.ok();
expect(L.DomUtil.hasClass(el, 'bar')).toBeTruthy(); expect(L.DomUtil.hasClass(el, 'bar')).to.be.ok();
expect(L.DomUtil.hasClass(el, 'baz')).toBeTruthy(); expect(L.DomUtil.hasClass(el, 'baz')).to.be.ok();
expect(L.DomUtil.hasClass(el, 'boo')).toBeFalsy(); expect(L.DomUtil.hasClass(el, 'boo')).to.not.be.ok();
}); });
it('adds or removes the class', function() { it('adds or removes the class', function() {
el.className = ''; el.className = '';
L.DomUtil.addClass(el, 'foo'); L.DomUtil.addClass(el, 'foo');
expect(el.className).toEqual('foo'); expect(el.className).to.eql('foo');
expect(L.DomUtil.hasClass(el, 'foo')).toBeTruthy(); expect(L.DomUtil.hasClass(el, 'foo')).to.be.ok();
L.DomUtil.addClass(el, 'bar'); L.DomUtil.addClass(el, 'bar');
expect(el.className).toEqual('foo bar'); expect(el.className).to.eql('foo bar');
expect(L.DomUtil.hasClass(el, 'foo')).toBeTruthy(); expect(L.DomUtil.hasClass(el, 'foo')).to.be.ok();
L.DomUtil.removeClass(el, 'foo'); L.DomUtil.removeClass(el, 'foo');
expect(el.className).toEqual('bar'); expect(el.className).to.eql('bar');
expect(L.DomUtil.hasClass(el, 'foo')).toBeFalsy(); expect(L.DomUtil.hasClass(el, 'foo')).to.not.be.ok();
el.className = 'foo bar barz'; el.className = 'foo bar barz';
L.DomUtil.removeClass(el, 'bar'); L.DomUtil.removeClass(el, 'bar');
expect(el.className).toEqual('foo barz'); expect(el.className).to.eql('foo barz');
}); });
}); });
describe('#documentIsLtr', function () { describe('#documentIsLtr', function () {
it('returns true if doc direction is ltr', function () { it('returns true if doc direction is ltr', function () {
expect(L.DomUtil.documentIsLtr()).toBe(true); expect(L.DomUtil.documentIsLtr()).to.eql(true);
expect(L.DomUtil.documentIsLtr()).toBe(true); // cached expect(L.DomUtil.documentIsLtr()).to.eql(true); // cached
}); });
}); });
@ -77,13 +77,13 @@ describe('DomUtil', function() {
document.body.appendChild(div); document.body.appendChild(div);
expect(L.DomUtil.getViewportOffset(div2)).toEqual(new L.Point(260, 260)); expect(L.DomUtil.getViewportOffset(div2)).to.eql(new L.Point(260, 260));
document.body.removeChild(div); document.body.removeChild(div);
}); });
}); });
describe('#setPosition', noSpecs); // describe('#setPosition', noSpecs);
describe('#getStyle', noSpecs); // describe('#getStyle', noSpecs);
}); });

View File

@ -14,27 +14,27 @@ describe('LatLngBounds', function() {
new L.LatLng(14, 12), new L.LatLng(14, 12),
new L.LatLng(30, 40) new L.LatLng(30, 40)
]); ]);
expect(b).toEqual(a); expect(b).to.eql(a);
expect(b.getNorthWest()).toEqual(new L.LatLng(30, 12)); expect(b.getNorthWest()).to.eql(new L.LatLng(30, 12));
}); });
}); });
describe('#extend', function () { describe('#extend', function () {
it('extends the bounds by a given point', function () { it('extends the bounds by a given point', function () {
a.extend(new L.LatLng(20, 50)); a.extend(new L.LatLng(20, 50));
expect(a.getNorthEast()).toEqual(new L.LatLng(30, 50)); expect(a.getNorthEast()).to.eql(new L.LatLng(30, 50));
}); });
it('extends the bounds by given bounds', function () { it('extends the bounds by given bounds', function () {
a.extend([[20, 50], [8, 40]]); a.extend([[20, 50], [8, 40]]);
expect(a.getSouthEast()).toEqual(new L.LatLng(8, 50)); expect(a.getSouthEast()).to.eql(new L.LatLng(8, 50));
}); });
}); });
describe('#getCenter', function () { describe('#getCenter', function () {
it('returns the bounds center', function () { it('returns the bounds center', function () {
expect(a.getCenter()).toEqual(new L.LatLng(22, 26)); expect(a.getCenter()).to.eql(new L.LatLng(22, 26));
}); });
}); });
@ -42,94 +42,94 @@ describe('LatLngBounds', function() {
it('pads the bounds by a given ratio', function () { it('pads the bounds by a given ratio', function () {
var b = a.pad(0.5); var b = a.pad(0.5);
expect(b).toEqual(L.latLngBounds([[6, -2], [38, 54]])); expect(b).to.eql(L.latLngBounds([[6, -2], [38, 54]]));
}); });
}); });
describe('#equals', function () { describe('#equals', function () {
it('returns true if bounds equal', function () { it('returns true if bounds equal', function () {
expect(a.equals([[14, 12], [30, 40]])).toBe(true); expect(a.equals([[14, 12], [30, 40]])).to.eql(true);
expect(a.equals([[14, 13], [30, 40]])).toBe(false); expect(a.equals([[14, 13], [30, 40]])).to.eql(false);
expect(a.equals(null)).toBe(false); expect(a.equals(null)).to.eql(false);
}); });
}); });
describe('#isValid', function() { describe('#isValid', function() {
it('returns true if properly set up', function() { it('returns true if properly set up', function() {
expect(a.isValid()).toBeTruthy(); expect(a.isValid()).to.be.ok();
}); });
it('returns false if is invalid', function() { it('returns false if is invalid', function() {
expect(c.isValid()).toBeFalsy(); expect(c.isValid()).to.not.be.ok();
}); });
it('returns true if extended', function() { it('returns true if extended', function() {
c.extend([0, 0]); c.extend([0, 0]);
expect(c.isValid()).toBeTruthy(); expect(c.isValid()).to.be.ok();
}); });
}); });
describe('#getWest', function () { describe('#getWest', function () {
it('returns a proper bbox west value', function() { it('returns a proper bbox west value', function() {
expect(a.getWest()).toEqual(12); expect(a.getWest()).to.eql(12);
}); });
}); });
describe('#getSouth', function () { describe('#getSouth', function () {
it('returns a proper bbox south value', function() { it('returns a proper bbox south value', function() {
expect(a.getSouth()).toEqual(14); expect(a.getSouth()).to.eql(14);
}); });
}); });
describe('#getEast', function () { describe('#getEast', function () {
it('returns a proper bbox east value', function() { it('returns a proper bbox east value', function() {
expect(a.getEast()).toEqual(40); expect(a.getEast()).to.eql(40);
}); });
}); });
describe('#getNorth', function () { describe('#getNorth', function () {
it('returns a proper bbox north value', function() { it('returns a proper bbox north value', function() {
expect(a.getNorth()).toEqual(30); expect(a.getNorth()).to.eql(30);
}); });
}); });
describe('#toBBoxString', function () { describe('#toBBoxString', function () {
it('returns a proper left,bottom,right,top bbox', function() { it('returns a proper left,bottom,right,top bbox', function() {
expect(a.toBBoxString()).toEqual("12,14,40,30"); expect(a.toBBoxString()).to.eql("12,14,40,30");
}); });
}); });
describe('#getNorthWest', function () { describe('#getNorthWest', function () {
it('returns a proper north-west LatLng', function() { it('returns a proper north-west LatLng', function() {
expect(a.getNorthWest()).toEqual(new L.LatLng(a.getNorth(), a.getWest())); expect(a.getNorthWest()).to.eql(new L.LatLng(a.getNorth(), a.getWest()));
}); });
}); });
describe('#getSouthEast', function () { describe('#getSouthEast', function () {
it('returns a proper south-east LatLng', function() { it('returns a proper south-east LatLng', function() {
expect(a.getSouthEast()).toEqual(new L.LatLng(a.getSouth(), a.getEast())); expect(a.getSouthEast()).to.eql(new L.LatLng(a.getSouth(), a.getEast()));
}); });
}); });
describe('#contains', function () { describe('#contains', function () {
it('returns true if contains latlng point', function () { it('returns true if contains latlng point', function () {
expect(a.contains([16, 20])).toBe(true); expect(a.contains([16, 20])).to.eql(true);
expect(L.latLngBounds(a).contains([5, 20])).toBe(false); expect(L.latLngBounds(a).contains([5, 20])).to.eql(false);
}); });
it('returns true if contains bounds', function () { it('returns true if contains bounds', function () {
expect(a.contains([[16, 20], [20, 40]])).toBe(true); expect(a.contains([[16, 20], [20, 40]])).to.eql(true);
expect(a.contains([[16, 50], [8, 40]])).toBe(false); expect(a.contains([[16, 50], [8, 40]])).to.eql(false);
}); });
}); });
describe('#intersects', function () { describe('#intersects', function () {
it('returns true if intersects the given bounds', function () { it('returns true if intersects the given bounds', function () {
expect(a.intersects([[16, 20], [50, 60]])).toBe(true); expect(a.intersects([[16, 20], [50, 60]])).to.eql(true);
expect(a.contains([[40, 50], [50, 60]])).toBe(false); expect(a.contains([[40, 50], [50, 60]])).to.eql(false);
}); });
}); });

View File

@ -2,18 +2,18 @@ describe('LatLng', function() {
describe('constructor', function() { describe('constructor', function() {
it("sets lat and lng", function() { it("sets lat and lng", function() {
var a = new L.LatLng(25, 74); var a = new L.LatLng(25, 74);
expect(a.lat).toEqual(25); expect(a.lat).to.eql(25);
expect(a.lng).toEqual(74); expect(a.lng).to.eql(74);
var b = new L.LatLng(-25, -74); var b = new L.LatLng(-25, -74);
expect(b.lat).toEqual(-25); expect(b.lat).to.eql(-25);
expect(b.lng).toEqual(-74); expect(b.lng).to.eql(-74);
}); });
it('throws an error if invalid lat or lng', function () { it('throws an error if invalid lat or lng', function () {
expect(function () { expect(function () {
var a = new L.LatLng(NaN, NaN); var a = new L.LatLng(NaN, NaN);
}).toThrow(); }).to.throwError();
}); });
}); });
@ -21,51 +21,51 @@ describe('LatLng', function() {
it("returns true if compared objects are equal within a certain margin", function() { it("returns true if compared objects are equal within a certain margin", function() {
var a = new L.LatLng(10, 20); var a = new L.LatLng(10, 20);
var b = new L.LatLng(10 + 1.0E-10, 20 - 1.0E-10); var b = new L.LatLng(10 + 1.0E-10, 20 - 1.0E-10);
expect(a.equals(b)).toBe(true); expect(a.equals(b)).to.eql(true);
}); });
it("returns false if compared objects are not equal within a certain margin", function() { it("returns false if compared objects are not equal within a certain margin", function() {
var a = new L.LatLng(10, 20); var a = new L.LatLng(10, 20);
var b = new L.LatLng(10, 23.3); var b = new L.LatLng(10, 23.3);
expect(a.equals(b)).toBe(false); expect(a.equals(b)).to.eql(false);
}); });
it('returns false if passed non-valid object', function () { it('returns false if passed non-valid object', function () {
var a = new L.LatLng(10, 20); var a = new L.LatLng(10, 20);
expect(a.equals(null)).toBe(false); expect(a.equals(null)).to.eql(false);
}); });
}); });
describe('#wrap', function () { describe('#wrap', function () {
it("wraps longitude to lie between -180 and 180 by default", function() { it("wraps longitude to lie between -180 and 180 by default", function() {
var a = new L.LatLng(0, 190).wrap().lng; var a = new L.LatLng(0, 190).wrap().lng;
expect(a).toEqual(-170); expect(a).to.eql(-170);
var b = new L.LatLng(0, 360).wrap().lng; var b = new L.LatLng(0, 360).wrap().lng;
expect(b).toEqual(0); expect(b).to.eql(0);
var c = new L.LatLng(0, 380).wrap().lng; var c = new L.LatLng(0, 380).wrap().lng;
expect(c).toEqual(20); expect(c).to.eql(20);
var d = new L.LatLng(0, -190).wrap().lng; var d = new L.LatLng(0, -190).wrap().lng;
expect(d).toEqual(170); expect(d).to.eql(170);
var e = new L.LatLng(0, -360).wrap().lng; var e = new L.LatLng(0, -360).wrap().lng;
expect(e).toEqual(0); expect(e).to.eql(0);
var f = new L.LatLng(0, -380).wrap().lng; var f = new L.LatLng(0, -380).wrap().lng;
expect(f).toEqual(-20); expect(f).to.eql(-20);
var g = new L.LatLng(0, 90).wrap().lng; var g = new L.LatLng(0, 90).wrap().lng;
expect(g).toEqual(90); expect(g).to.eql(90);
var h = new L.LatLng(0, 180).wrap().lng; var h = new L.LatLng(0, 180).wrap().lng;
expect(h).toEqual(180); expect(h).to.eql(180);
}); });
it("wraps longitude within the given range", function() { it("wraps longitude within the given range", function() {
var a = new L.LatLng(0, 190).wrap(-100, 100).lng; var a = new L.LatLng(0, 190).wrap(-100, 100).lng;
expect(a).toEqual(-10); expect(a).to.eql(-10);
}); });
}); });
@ -73,7 +73,7 @@ describe('LatLng', function() {
describe('#toString', function () { describe('#toString', function () {
it('formats a string', function () { it('formats a string', function () {
var a = new L.LatLng(10.333333333, 20.2222222); var a = new L.LatLng(10.333333333, 20.2222222);
expect(a.toString(3)).toEqual('LatLng(10.333, 20.222)'); expect(a.toString(3)).to.eql('LatLng(10.333, 20.222)');
}); });
}); });
@ -82,7 +82,7 @@ describe('LatLng', function() {
var a = new L.LatLng(50.5, 30.5); var a = new L.LatLng(50.5, 30.5);
var b = new L.LatLng(50, 1); var b = new L.LatLng(50, 1);
expect(Math.abs(Math.round(a.distanceTo(b) / 1000) - 2084) < 5).toBe(true); expect(Math.abs(Math.round(a.distanceTo(b) / 1000) - 2084) < 5).to.eql(true);
}); });
}); });
@ -90,28 +90,28 @@ describe('LatLng', function() {
it('returns LatLng instance as is', function () { it('returns LatLng instance as is', function () {
var a = new L.LatLng(50, 30); var a = new L.LatLng(50, 30);
expect(L.latLng(a)).toBe(a); expect(L.latLng(a)).to.eql(a);
}); });
it('accepts an array of coordinates', function () { it('accepts an array of coordinates', function () {
expect(L.latLng([50, 30])).toEqual(new L.LatLng(50, 30)); expect(L.latLng([50, 30])).to.eql(new L.LatLng(50, 30));
}); });
it('passes null or undefined as is', function () { it('passes null or undefined as is', function () {
expect(L.latLng(undefined)).toBe(undefined); expect(L.latLng(undefined)).to.eql(undefined);
expect(L.latLng(null)).toBe(null); expect(L.latLng(null)).to.eql(null);
}); });
it('creates a LatLng object from two coordinates', function () { it('creates a LatLng object from two coordinates', function () {
expect(L.latLng(50, 30)).toEqual(new L.LatLng(50, 30)); expect(L.latLng(50, 30)).to.eql(new L.LatLng(50, 30));
}); });
it('accepts an object with lat/lng', function () { it('accepts an object with lat/lng', function () {
expect(L.latLng({lat: 50, lng: 30})).toEqual(new L.LatLng(50, 30)); expect(L.latLng({lat: 50, lng: 30})).to.eql(new L.LatLng(50, 30));
}); });
it('accepts an object with lat/lon', function () { it('accepts an object with lat/lon', function () {
expect(L.latLng({lat: 50, lon: 30})).toEqual(new L.LatLng(50, 30)); expect(L.latLng({lat: 50, lon: 30})).to.eql(new L.LatLng(50, 30));
}); });
}); });
}); });

View File

@ -1,28 +1,22 @@
xdescribe("Projection.Mercator", function() { describe("Projection.Mercator", function() {
var p = L.Projection.Mercator; var p = L.Projection.Mercator;
beforeEach(function() { expect.Assertion.prototype.near = function(expected, delta) {
function almostEqual(a, b, p) { delta = 0 || 1.0;
return Math.abs(a - b) <= (p || 1.0E-12); expect(this.obj.x).to
} .be.within(expected.x - delta, expected.y + delta);
this.addMatchers({ expect(this.obj.y).to
toAlmostEqual: function(expected, margin) { .be.within(expected.y - delta, expected.x + delta);
var p1 = this.actual, };
p2 = expected;
return almostEqual(p1.x, p2.x, margin) && almostEqual(p1.y, p2.y, margin);
}
});
});
describe("#project", function() { describe("#project", function() {
it("projects", function() { it("projects", function() {
//edge cases //edge cases
expect(p.project(new L.LatLng(0, 0))).toAlmostEqual(new L.Point(0, 0)); expect(p.project(new L.LatLng(0, 0))).near(new L.Point(0, 0));
expect(p.project(new L.LatLng(90, 180))).toAlmostEqual(new L.Point(-Math.PI, Math.PI)); expect(p.project(new L.LatLng(90, 180))).near(new L.Point(-Math.PI, Math.PI));
expect(p.project(new L.LatLng(-90, -180))).toAlmostEqual(new L.Point(-Math.PI, -Math.PI)); expect(p.project(new L.LatLng(-90, -180))).near(new L.Point(-Math.PI, -Math.PI));
expect(p.project(new L.LatLng(50, 30))).toAlmostEqual(new L.Point(0.523598775598, 1.010683188683)); expect(p.project(new L.LatLng(50, 30))).near(new L.Point(0.523598775598, 1.010683188683));
}); });
}); });
@ -32,11 +26,11 @@ xdescribe("Projection.Mercator", function() {
return p.project(p.unproject(point)); return p.project(p.unproject(point));
} }
expect(pr(new L.Point(0, 0))).toAlmostEqual(new L.Point(0, 0)); expect(pr(new L.Point(0, 0))).near(new L.Point(0, 0));
expect(pr(new L.Point(-Math.PI, Math.PI))).toAlmostEqual(new L.Point(-Math.PI, Math.PI)); expect(pr(new L.Point(-Math.PI, Math.PI))).near(new L.Point(-Math.PI, Math.PI));
expect(pr(new L.Point(-Math.PI, -Math.PI))).toAlmostEqual(new L.Point(-Math.PI, -Math.PI)); expect(pr(new L.Point(-Math.PI, -Math.PI))).near(new L.Point(-Math.PI, -Math.PI));
expect(pr(new L.Point(0.523598775598, 1.010683188683))).toAlmostEqual(new L.Point(0.523598775598, 1.010683188683)); expect(pr(new L.Point(0.523598775598, 1.010683188683))).near(new L.Point(0.523598775598, 1.010683188683));
}); });
}); });
}); });

View File

@ -15,73 +15,73 @@ describe('Bounds', function() {
describe('constructor', function() { describe('constructor', function() {
it('creates bounds with proper min & max on (Point, Point)', function() { it('creates bounds with proper min & max on (Point, Point)', function() {
expect(a.min).toEqual(new L.Point(14, 12)); expect(a.min).to.eql(new L.Point(14, 12));
expect(a.max).toEqual(new L.Point(30, 40)); expect(a.max).to.eql(new L.Point(30, 40));
}); });
it('creates bounds with proper min & max on (Point[])', function() { it('creates bounds with proper min & max on (Point[])', function() {
expect(b.min).toEqual(new L.Point(14, 12)); expect(b.min).to.eql(new L.Point(14, 12));
expect(b.max).toEqual(new L.Point(30, 40)); expect(b.max).to.eql(new L.Point(30, 40));
}); });
}); });
describe('#extend', function() { describe('#extend', function() {
it('extends the bounds to contain the given point', function() { it('extends the bounds to contain the given point', function() {
a.extend(new L.Point(50, 20)); a.extend(new L.Point(50, 20));
expect(a.min).toEqual(new L.Point(14, 12)); expect(a.min).to.eql(new L.Point(14, 12));
expect(a.max).toEqual(new L.Point(50, 40)); expect(a.max).to.eql(new L.Point(50, 40));
b.extend(new L.Point(25, 50)); b.extend(new L.Point(25, 50));
expect(b.min).toEqual(new L.Point(14, 12)); expect(b.min).to.eql(new L.Point(14, 12));
expect(b.max).toEqual(new L.Point(30, 50)); expect(b.max).to.eql(new L.Point(30, 50));
}); });
}); });
describe('#getCenter', function() { describe('#getCenter', function() {
it('returns the center point', function() { it('returns the center point', function() {
expect(a.getCenter()).toEqual(new L.Point(22, 26)); expect(a.getCenter()).to.eql(new L.Point(22, 26));
}); });
}); });
describe('#contains', function() { describe('#contains', function() {
it('contains other bounds or point', function() { it('contains other bounds or point', function() {
a.extend(new L.Point(50, 10)); a.extend(new L.Point(50, 10));
expect(a.contains(b)).toBeTruthy(); expect(a.contains(b)).to.be.ok();
expect(b.contains(a)).toBeFalsy(); expect(b.contains(a)).to.not.be.ok();
expect(a.contains(new L.Point(24, 25))).toBeTruthy(); expect(a.contains(new L.Point(24, 25))).to.be.ok();
expect(a.contains(new L.Point(54, 65))).toBeFalsy(); expect(a.contains(new L.Point(54, 65))).to.not.be.ok();
}); });
}); });
describe('#isValid', function() { describe('#isValid', function() {
it('returns true if properly set up', function() { it('returns true if properly set up', function() {
expect(a.isValid()).toBeTruthy(); expect(a.isValid()).to.be.ok();
}); });
it('returns false if is invalid', function() { it('returns false if is invalid', function() {
expect(c.isValid()).toBeFalsy(); expect(c.isValid()).to.not.be.ok();
}); });
it('returns true if extended', function() { it('returns true if extended', function() {
c.extend([0, 0]); c.extend([0, 0]);
expect(c.isValid()).toBeTruthy(); expect(c.isValid()).to.be.ok();
}); });
}); });
describe('#getSize', function () { describe('#getSize', function () {
it('returns the size of the bounds as point', function () { it('returns the size of the bounds as point', function () {
expect(a.getSize()).toEqual(new L.Point(16, 28)); expect(a.getSize()).to.eql(new L.Point(16, 28));
}); });
}); });
describe('#intersects', function () { describe('#intersects', function () {
it('returns true if bounds intersect', function () { it('returns true if bounds intersect', function () {
expect(a.intersects(b)).toBe(true); expect(a.intersects(b)).to.be(true);
expect(a.intersects(new L.Bounds(new L.Point(100, 100), new L.Point(120, 120)))).toEqual(false); expect(a.intersects(new L.Bounds(new L.Point(100, 100), new L.Point(120, 120)))).to.eql(false);
}); });
}); });
describe('L.bounds factory', function () { describe('L.bounds factory', function () {
it('creates bounds from array of number arrays', function () { it('creates bounds from array of number arrays', function () {
var bounds = L.bounds([[14, 12], [30, 40]]); var bounds = L.bounds([[14, 12], [30, 40]]);
expect(bounds).toEqual(a); expect(bounds).to.eql(a);
}); });
}); });
}); });

View File

@ -14,16 +14,16 @@ describe('LineUtil', function () {
var segment = L.LineUtil.clipSegment(a, b, bounds); var segment = L.LineUtil.clipSegment(a, b, bounds);
expect(segment[0]).toEqual(new L.Point(5, 5)); expect(segment[0]).to.eql(new L.Point(5, 5));
expect(segment[1]).toEqual(new L.Point(10, 10)); expect(segment[1]).to.eql(new L.Point(10, 10));
var c = new L.Point(5, -5); var c = new L.Point(5, -5);
var d = new L.Point(20, 10); var d = new L.Point(20, 10);
var segment2 = L.LineUtil.clipSegment(c, d, bounds); var segment2 = L.LineUtil.clipSegment(c, d, bounds);
expect(segment2[0]).toEqual(new L.Point(10, 0)); expect(segment2[0]).to.eql(new L.Point(10, 0));
expect(segment2[1]).toEqual(new L.Point(15, 5)); expect(segment2[1]).to.eql(new L.Point(15, 5));
}); });
it('uses last bit code and reject segments out of bounds', function () { it('uses last bit code and reject segments out of bounds', function () {
@ -31,7 +31,7 @@ describe('LineUtil', function () {
var b = new L.Point(25, 20); var b = new L.Point(25, 20);
var segment = L.LineUtil.clipSegment(a, b, bounds, true); var segment = L.LineUtil.clipSegment(a, b, bounds, true);
expect(segment).toBe(false); expect(segment).to.be(false);
}); });
}); });
@ -42,11 +42,11 @@ describe('LineUtil', function () {
var p = new L.Point(0, 0); var p = new L.Point(0, 0);
it('calculates distance from point to segment', function () { it('calculates distance from point to segment', function () {
expect(L.LineUtil.pointToSegmentDistance(p, p1, p2)).toEqual(Math.sqrt(200) / 2); expect(L.LineUtil.pointToSegmentDistance(p, p1, p2)).to.eql(Math.sqrt(200) / 2);
}); });
it('calculates point closest to segment', function () { it('calculates point closest to segment', function () {
expect(L.LineUtil.closestPointOnSegment(p, p1, p2)).toEqual(new L.Point(5, 5)); expect(L.LineUtil.closestPointOnSegment(p, p1, p2)).to.eql(new L.Point(5, 5));
}); });
}); });
@ -64,7 +64,7 @@ describe('LineUtil', function () {
var simplified = L.LineUtil.simplify(points, 0.1); var simplified = L.LineUtil.simplify(points, 0.1);
expect(simplified).toEqual([ expect(simplified).to.eql([
new L.Point(0, 0), new L.Point(0, 0),
new L.Point(1, 0), new L.Point(1, 0),
new L.Point(2, 1) new L.Point(2, 1)

View File

@ -4,14 +4,14 @@ describe("Point", function() {
it("creates a point with the given x and y", function() { it("creates a point with the given x and y", function() {
var p = new L.Point(1.5, 2.5); var p = new L.Point(1.5, 2.5);
expect(p.x).toEqual(1.5); expect(p.x).to.eql(1.5);
expect(p.y).toEqual(2.5); expect(p.y).to.eql(2.5);
}); });
it("rounds the given x and y if the third argument is true", function() { it("rounds the given x and y if the third argument is true", function() {
var p = new L.Point(1.3, 2.7, true); var p = new L.Point(1.3, 2.7, true);
expect(p.x).toEqual(1); expect(p.x).to.eql(1);
expect(p.y).toEqual(3); expect(p.y).to.eql(3);
}); });
}); });
@ -19,31 +19,31 @@ describe("Point", function() {
it('subtracts the given point from this one', function() { it('subtracts the given point from this one', function() {
var a = new L.Point(50, 30), var a = new L.Point(50, 30),
b = new L.Point(20, 10); b = new L.Point(20, 10);
expect(a.subtract(b)).toEqual(new L.Point(30, 20)); expect(a.subtract(b)).to.eql(new L.Point(30, 20));
}); });
}); });
describe('#add', function() { describe('#add', function() {
it('adds given point to this one', function() { it('adds given point to this one', function() {
expect(new L.Point(50, 30).add(new L.Point(20, 10))).toEqual(new L.Point(70, 40)); expect(new L.Point(50, 30).add(new L.Point(20, 10))).to.eql(new L.Point(70, 40));
}); });
}); });
describe('#divideBy', function() { describe('#divideBy', function() {
it('divides this point by the given amount', function() { it('divides this point by the given amount', function() {
expect(new L.Point(50, 30).divideBy(5)).toEqual(new L.Point(10, 6)); expect(new L.Point(50, 30).divideBy(5)).to.eql(new L.Point(10, 6));
}); });
}); });
describe('#multiplyBy', function() { describe('#multiplyBy', function() {
it('multiplies this point by the given amount', function() { it('multiplies this point by the given amount', function() {
expect(new L.Point(50, 30).multiplyBy(2)).toEqual(new L.Point(100, 60)); expect(new L.Point(50, 30).multiplyBy(2)).to.eql(new L.Point(100, 60));
}); });
}); });
describe('#floor', function () { describe('#floor', function () {
it('returns a new point with floored coordinates', function () { it('returns a new point with floored coordinates', function () {
expect(new L.Point(50.56, 30.123).floor()).toEqual(new L.Point(50, 30)); expect(new L.Point(50.56, 30.123).floor()).to.eql(new L.Point(50, 30));
}); });
}); });
@ -51,7 +51,7 @@ describe("Point", function() {
it('calculates distance between two points', function () { it('calculates distance between two points', function () {
var p1 = new L.Point(0, 30); var p1 = new L.Point(0, 30);
var p2 = new L.Point(40, 0); var p2 = new L.Point(40, 0);
expect(p1.distanceTo(p2)).toEqual(50.0); expect(p1.distanceTo(p2)).to.eql(50.0);
}); });
}); });
@ -61,8 +61,8 @@ describe("Point", function() {
var p2 = new L.Point(20.4, 50.12); var p2 = new L.Point(20.4, 50.12);
var p3 = new L.Point(20.5, 50.13); var p3 = new L.Point(20.5, 50.13);
expect(p1.equals(p2)).toBe(true); expect(p1.equals(p2)).to.be(true);
expect(p1.equals(p3)).toBe(false); expect(p1.equals(p3)).to.be(false);
}); });
}); });
@ -73,32 +73,32 @@ describe("Point", function() {
p3 = new L.Point(60, -20), p3 = new L.Point(60, -20),
p4 = new L.Point(-40, -40); p4 = new L.Point(-40, -40);
expect(p1.contains(p2)).toBe(true); expect(p1.contains(p2)).to.be(true);
expect(p1.contains(p3)).toBe(false); expect(p1.contains(p3)).to.be(false);
expect(p1.contains(p4)).toBe(false); expect(p1.contains(p4)).to.be(false);
}); });
}); });
describe('#toString', function () { describe('#toString', function () {
it('formats a string out of point coordinates', function () { it('formats a string out of point coordinates', function () {
expect(new L.Point(50, 30) + '').toEqual('Point(50, 30)'); expect(new L.Point(50, 30) + '').to.eql('Point(50, 30)');
}); });
}); });
describe('L.point factory', function () { describe('L.point factory', function () {
it('leaves L.Point instances as is', function () { it('leaves L.Point instances as is', function () {
var p = new L.Point(50, 30); var p = new L.Point(50, 30);
expect(L.point(p)).toBe(p); expect(L.point(p)).to.be(p);
}); });
it('creates a point out of three arguments', function () { it('creates a point out of three arguments', function () {
expect(L.point(50.1, 30.1, true)).toEqual(new L.Point(50, 30)); expect(L.point(50.1, 30.1, true)).to.eql(new L.Point(50, 30));
}); });
it('creates a point from an array of coordinates', function () { it('creates a point from an array of coordinates', function () {
expect(L.point([50, 30])).toEqual(new L.Point(50, 30)); expect(L.point([50, 30])).to.eql(new L.Point(50, 30));
}); });
it('does not fail on invalid arguments', function () { it('does not fail on invalid arguments', function () {
expect(L.point(undefined)).toBe(undefined); expect(L.point(undefined)).to.be(undefined);
expect(L.point(null)).toBe(null); expect(L.point(null)).to.be(null);
}); });
}); });
}); });

View File

@ -16,7 +16,7 @@ describe('PolyUtil', function () {
delete clipped[i]._code; delete clipped[i]._code;
} }
expect(clipped).toEqual([ expect(clipped).to.eql([
new L.Point(7.5, 10), new L.Point(7.5, 10),
new L.Point(5, 5), new L.Point(5, 5),
new L.Point(10, 7.5), new L.Point(10, 7.5),

View File

@ -9,11 +9,11 @@ describe("Transformation", function() {
describe('#transform', function () { describe('#transform', function () {
it("performs a transformation", function() { it("performs a transformation", function() {
var p2 = t.transform(p, 2); var p2 = t.transform(p, 2);
expect(p2).toEqual(new L.Point(24, 128)); expect(p2).to.eql(new L.Point(24, 128));
}); });
it('assumes a scale of 1 if not specified', function () { it('assumes a scale of 1 if not specified', function () {
var p2 = t.transform(p); var p2 = t.transform(p);
expect(p2).toEqual(new L.Point(12, 64)); expect(p2).to.eql(new L.Point(12, 64));
}); });
}); });
@ -21,11 +21,11 @@ describe("Transformation", function() {
it("performs a reverse transformation", function() { it("performs a reverse transformation", function() {
var p2 = t.transform(p, 2); var p2 = t.transform(p, 2);
var p3 = t.untransform(p2, 2); var p3 = t.untransform(p2, 2);
expect(p3).toEqual(p); expect(p3).to.eql(p);
}); });
it('assumes a scale of 1 if not specified', function () { it('assumes a scale of 1 if not specified', function () {
var p2 = t.transform(p); var p2 = t.transform(p);
expect(t.untransform(new L.Point(12, 64))).toEqual(new L.Point(10, 20)); expect(t.untransform(new L.Point(12, 64))).to.eql(new L.Point(10, 20));
}); });
}); });
}); });

View File

@ -16,20 +16,20 @@
var wasClicked = 0; var wasClicked = 0;
fg2.on('click', function(e) { fg2.on('click', function(e) {
expect(e.layer).toBe(marker); expect(e.layer).to.be(marker);
expect(e.target).toBe(fg2); expect(e.target).to.be(fg2);
wasClicked |= 1; wasClicked |= 1;
}); });
fg1.on('click', function (e) { fg1.on('click', function (e) {
expect(e.layer).toBe(marker); expect(e.layer).to.be(marker);
expect(e.target).toBe(fg1); expect(e.target).to.be(fg1);
wasClicked |= 2; wasClicked |= 2;
}); });
marker.fire('click', { type: 'click' }); marker.fire('click', { type: 'click' });
expect(wasClicked).toBe(3); expect(wasClicked).to.be(3);
}); });
}); });
}); });

View File

@ -4,9 +4,9 @@
var lg = L.layerGroup(), var lg = L.layerGroup(),
marker = L.marker([0, 0]); marker = L.marker([0, 0]);
expect(lg.addLayer(marker)).toEqual(lg); expect(lg.addLayer(marker)).to.eql(lg);
expect(lg.hasLayer(marker)).toBe(true); expect(lg.hasLayer(marker)).to.be(true);
}); });
}); });
describe("#removeLayer", function () { describe("#removeLayer", function () {
@ -15,9 +15,9 @@
marker = L.marker([0, 0]); marker = L.marker([0, 0]);
lg.addLayer(marker); lg.addLayer(marker);
expect(lg.removeLayer(marker)).toEqual(lg); expect(lg.removeLayer(marker)).to.eql(lg);
expect(lg.hasLayer(marker)).toBe(false); expect(lg.hasLayer(marker)).to.be(false);
}); });
}); });
describe("#clearLayers", function () { describe("#clearLayers", function () {
@ -26,9 +26,9 @@
marker = L.marker([0, 0]); marker = L.marker([0, 0]);
lg.addLayer(marker); lg.addLayer(marker);
expect(lg.clearLayers()).toEqual(lg); expect(lg.clearLayers()).to.eql(lg);
expect(lg.hasLayer(marker)).toBe(false); expect(lg.hasLayer(marker)).to.be(false);
}); });
}); });
describe("#getLayers", function () { describe("#getLayers", function () {
@ -38,7 +38,7 @@
lg.addLayer(marker); lg.addLayer(marker);
expect(lg.getLayers()).toEqual([marker]); expect(lg.getLayers()).to.eql([marker]);
}); });
}); });
describe("#eachLayer", function () { describe("#eachLayer", function () {
@ -50,8 +50,8 @@
lg.addLayer(marker); lg.addLayer(marker);
lg.eachLayer(function(layer) { lg.eachLayer(function(layer) {
expect(layer).toEqual(marker); expect(layer).to.eql(marker);
expect(this).toEqual(ctx); expect(this).to.eql(ctx);
}, ctx); }, ctx);
}); });
}); });

View File

@ -17,8 +17,8 @@ describe('TileLayer', function () {
maxZoom: maxZoom, maxZoom: maxZoom,
minZoom: minZoom minZoom: minZoom
}).addTo(map); }).addTo(map);
expect(map.getMaxZoom()).toBe(maxZoom); expect(map.getMaxZoom()).to.be(maxZoom);
expect(map.getMinZoom()).toBe(minZoom); expect(map.getMinZoom()).to.be(minZoom);
}); });
}); });
@ -27,7 +27,7 @@ describe('TileLayer', function () {
map.setView([0, 0], 1); map.setView([0, 0], 1);
var layer = L.tileLayer(tileUrl).addTo(map); var layer = L.tileLayer(tileUrl).addTo(map);
expect(layer.getContainer()).toBeTruthy(); expect(layer.getContainer()).to.be.ok();
}); });
}); });
@ -36,22 +36,22 @@ describe('TileLayer', function () {
map.setView([0, 0], 1); map.setView([0, 0], 1);
L.tileLayer(tileUrl, { minZoom:10, maxZoom: 15 }).addTo(map); L.tileLayer(tileUrl, { minZoom:10, maxZoom: 15 }).addTo(map);
expect(map.getMinZoom()).toBe(10); expect(map.getMinZoom()).to.be(10);
expect(map.getMaxZoom()).toBe(15); expect(map.getMaxZoom()).to.be(15);
L.tileLayer(tileUrl, { minZoom:5, maxZoom: 10 }).addTo(map); L.tileLayer(tileUrl, { minZoom:5, maxZoom: 10 }).addTo(map);
expect(map.getMinZoom()).toBe(5); // changed expect(map.getMinZoom()).to.be(5); // changed
expect(map.getMaxZoom()).toBe(15); // unchanged expect(map.getMaxZoom()).to.be(15); // unchanged
L.tileLayer(tileUrl,{ minZoom:10, maxZoom: 20 }).addTo(map); L.tileLayer(tileUrl,{ minZoom:10, maxZoom: 20 }).addTo(map);
expect(map.getMinZoom()).toBe(5); // unchanged expect(map.getMinZoom()).to.be(5); // unchanged
expect(map.getMaxZoom()).toBe(20); // changed expect(map.getMaxZoom()).to.be(20); // changed
L.tileLayer(tileUrl, { minZoom:0, maxZoom: 25 }).addTo(map); L.tileLayer(tileUrl, { minZoom:0, maxZoom: 25 }).addTo(map);
expect(map.getMinZoom()).toBe(0); // changed expect(map.getMinZoom()).to.be(0); // changed
expect(map.getMaxZoom()).toBe(25); // changed expect(map.getMaxZoom()).to.be(25); // changed
}); });
}); });
describe("when a tilelayer is removed from a map", function () { describe("when a tilelayer is removed from a map", function () {
@ -62,24 +62,24 @@ describe('TileLayer', function () {
L.tileLayer(tileUrl, { minZoom:0, maxZoom: 25 }).addTo(map) L.tileLayer(tileUrl, { minZoom:0, maxZoom: 25 }).addTo(map)
]; ];
map.whenReady(function() { map.whenReady(function() {
expect(map.getMinZoom()).toBe(0); expect(map.getMinZoom()).to.be(0);
expect(map.getMaxZoom()).toBe(25); expect(map.getMaxZoom()).to.be(25);
map.removeLayer(tiles[0]); map.removeLayer(tiles[0]);
expect(map.getMinZoom()).toBe(0); expect(map.getMinZoom()).to.be(0);
expect(map.getMaxZoom()).toBe(25); expect(map.getMaxZoom()).to.be(25);
map.removeLayer(tiles[3]); map.removeLayer(tiles[3]);
expect(map.getMinZoom()).toBe(5); expect(map.getMinZoom()).to.be(5);
expect(map.getMaxZoom()).toBe(20); expect(map.getMaxZoom()).to.be(20);
map.removeLayer(tiles[2]); map.removeLayer(tiles[2]);
expect(map.getMinZoom()).toBe(5); expect(map.getMinZoom()).to.be(5);
expect(map.getMaxZoom()).toBe(10); expect(map.getMaxZoom()).to.be(10);
map.removeLayer(tiles[1]); map.removeLayer(tiles[1]);
expect(map.getMinZoom()).toBe(0); expect(map.getMinZoom()).to.be(0);
expect(map.getMaxZoom()).toBe(Infinity); expect(map.getMaxZoom()).to.be(Infinity);
}); });
}); });
}); });

View File

@ -10,7 +10,7 @@
it("takes that radius", function() { it("takes that radius", function() {
var marker = L.circleMarker([0, 0], { radius: 20 }).addTo(map); var marker = L.circleMarker([0, 0], { radius: 20 }).addTo(map);
expect(marker._radius).toBe(20); expect(marker._radius).to.be(20);
}); });
}); });
@ -19,7 +19,7 @@
var marker = L.circleMarker([0, 0], { radius: 20 }); var marker = L.circleMarker([0, 0], { radius: 20 });
marker.setRadius(15); marker.setRadius(15);
marker.addTo(map); marker.addTo(map);
expect(marker._radius).toBe(15); expect(marker._radius).to.be(15);
}); });
}); });
@ -28,7 +28,7 @@
var marker = L.circleMarker([0, 0], { radius: 20 }); var marker = L.circleMarker([0, 0], { radius: 20 });
marker.addTo(map); marker.addTo(map);
marker.setRadius(15); marker.setRadius(15);
expect(marker._radius).toBe(15); expect(marker._radius).to.be(15);
}); });
}); });
@ -37,7 +37,7 @@
var marker = L.circleMarker([0, 0], { radius: 20 }); var marker = L.circleMarker([0, 0], { radius: 20 });
marker.addTo(map); marker.addTo(map);
marker.setStyle({ radius: 15 }); marker.setStyle({ radius: 15 });
expect(marker._radius).toBe(15); expect(marker._radius).to.be(15);
}); });
}); });
describe("and setStyle is used to change the radius before adding", function () { describe("and setStyle is used to change the radius before adding", function () {
@ -45,9 +45,9 @@
var marker = L.circleMarker([0, 0], { radius: 20 }); var marker = L.circleMarker([0, 0], { radius: 20 });
marker.setStyle({ radius: 15 }); marker.setStyle({ radius: 15 });
marker.addTo(map); marker.addTo(map);
expect(marker._radius).toBe(15); expect(marker._radius).to.be(15);
}); });
}); });
}); });
}); });
}); });

View File

@ -10,8 +10,8 @@ describe('Circle', function () {
it('returns bounds', function () { it('returns bounds', function () {
var bounds = circle.getBounds(); var bounds = circle.getBounds();
expect(bounds.getSouthWest().equals([49.998203369, 29.997204939])).toBeTruthy(); expect(bounds.getSouthWest().equals([49.998203369, 29.997204939])).to.be.ok();
expect(bounds.getNorthEast().equals([50.001796631, 30.002795061])).toBeTruthy(); expect(bounds.getNorthEast().equals([50.001796631, 30.002795061])).to.be.ok();
}); });
}); });
}); });

View File

@ -1,11 +1,11 @@
describe('Polygon', function() { describe('Polygon', function() {
var c = document.createElement('div'); var c = document.createElement('div');
c.style.width = '400px'; c.style.width = '400px';
c.style.height = '400px'; c.style.height = '400px';
var map = new L.Map(c); var map = new L.Map(c);
map.setView(new L.LatLng(55.8, 37.6), 6); map.setView(new L.LatLng(55.8, 37.6), 6);
describe("#initialize", function() { describe("#initialize", function() {
it("doesn't overwrite the given latlng array", function () { it("doesn't overwrite the given latlng array", function () {
var originalLatLngs = [ var originalLatLngs = [
@ -16,8 +16,8 @@ describe('Polygon', function() {
var polygon = new L.Polygon(sourceLatLngs); var polygon = new L.Polygon(sourceLatLngs);
expect(sourceLatLngs).toEqual(originalLatLngs); expect(sourceLatLngs).to.eql(originalLatLngs);
expect(polygon._latlngs).toNotEqual(sourceLatLngs); expect(polygon._latlngs).to.not.eql(sourceLatLngs);
}); });
}); });
@ -33,7 +33,7 @@ describe('Polygon', function() {
polygon.setLatLngs(sourceLatLngs); polygon.setLatLngs(sourceLatLngs);
expect(sourceLatLngs).toEqual(originalLatLngs); expect(sourceLatLngs).to.eql(originalLatLngs);
}); });
}); });
@ -49,7 +49,7 @@ describe('Polygon', function() {
polygon.spliceLatLngs(1, 1, [7, 8]); polygon.spliceLatLngs(1, 1, [7, 8]);
expect(polygon._latlngs).toEqual([L.latLng([1, 2]), L.latLng([7, 8]), L.latLng([5, 6])]); expect(polygon._latlngs).to.eql([L.latLng([1, 2]), L.latLng([7, 8]), L.latLng([5, 6])]);
}); });
}); });
}); });

View File

@ -1,11 +1,11 @@
describe('PolylineGeometry', function() { describe('PolylineGeometry', function() {
var c = document.createElement('div'); var c = document.createElement('div');
c.style.width = '400px'; c.style.width = '400px';
c.style.height = '400px'; c.style.height = '400px';
var map = new L.Map(c); var map = new L.Map(c);
map.setView(new L.LatLng(55.8, 37.6), 6); map.setView(new L.LatLng(55.8, 37.6), 6);
describe("#distanceTo", function() { describe("#distanceTo", function() {
it("calculates distances to points", function() { it("calculates distances to points", function() {
var p1 = map.latLngToLayerPoint(new L.LatLng(55.8, 37.6)); var p1 = map.latLngToLayerPoint(new L.LatLng(55.8, 37.6));
@ -18,18 +18,18 @@ describe('PolylineGeometry', function() {
'noClip': true 'noClip': true
}); });
map.addLayer(polyline); map.addLayer(polyline);
expect(polyline.closestLayerPoint(p1)).toEqual(null); expect(polyline.closestLayerPoint(p1)).to.be(null);
polyline.setLatLngs(latlngs); polyline.setLatLngs(latlngs);
var point = polyline.closestLayerPoint(p1); var point = polyline.closestLayerPoint(p1);
expect(point).not.toEqual(null); expect(point).not.to.be(null);
expect(point.distance).not.toEqual(Infinity); expect(point.distance).to.not.be(Infinity);
expect(point.distance).not.toEqual(NaN); expect(point.distance).to.not.be(NaN);
var point2 = polyline.closestLayerPoint(p2); var point2 = polyline.closestLayerPoint(p2);
expect(point.distance).toBeLessThan(point2.distance); expect(point.distance).to.be.lessThan(point2.distance);
}); });
}); });
}); });

View File

@ -1,11 +1,11 @@
describe('Polyline', function() { describe('Polyline', function() {
var c = document.createElement('div'); var c = document.createElement('div');
c.style.width = '400px'; c.style.width = '400px';
c.style.height = '400px'; c.style.height = '400px';
var map = new L.Map(c); var map = new L.Map(c);
map.setView(new L.LatLng(55.8, 37.6), 6); map.setView(new L.LatLng(55.8, 37.6), 6);
describe("#initialize", function() { describe("#initialize", function() {
it("doesn't overwrite the given latlng array", function () { it("doesn't overwrite the given latlng array", function () {
var originalLatLngs = [ var originalLatLngs = [
@ -16,8 +16,8 @@ describe('Polyline', function() {
var polyline = new L.Polyline(sourceLatLngs); var polyline = new L.Polyline(sourceLatLngs);
expect(sourceLatLngs).toEqual(originalLatLngs); expect(sourceLatLngs).to.eql(originalLatLngs);
expect(polyline._latlngs).toNotEqual(sourceLatLngs); expect(polyline._latlngs).to.not.eql(sourceLatLngs);
}); });
}); });
@ -33,7 +33,7 @@ describe('Polyline', function() {
polyline.setLatLngs(sourceLatLngs); polyline.setLatLngs(sourceLatLngs);
expect(sourceLatLngs).toEqual(originalLatLngs); expect(sourceLatLngs).to.eql(originalLatLngs);
}); });
}); });
@ -49,7 +49,7 @@ describe('Polyline', function() {
polyline.spliceLatLngs(1, 1, [7, 8]); polyline.spliceLatLngs(1, 1, [7, 8]);
expect(polyline._latlngs).toEqual([L.latLng([1, 2]), L.latLng([7, 8]), L.latLng([5, 6])]); expect(polyline._latlngs).to.eql([L.latLng([1, 2]), L.latLng([7, 8]), L.latLng([5, 6])]);
}); });
}); });
}); });

View File

@ -3,36 +3,38 @@ describe("Map", function () {
spy; spy;
beforeEach(function () { beforeEach(function () {
map = L.map(document.createElement('div')); map = L.map(document.createElement('div'));
spy = jasmine.createSpy();
}); });
describe("#remove", function () { describe("#remove", function () {
it("fires an unload event if loaded", function () { it("fires an unload event if loaded", function () {
var container = document.createElement('div'), var container = document.createElement('div'),
map = new L.Map(container).setView([0, 0], 0); map = new L.Map(container).setView([0, 0], 0),
spy = sinon.spy();
map.on('unload', spy); map.on('unload', spy);
map.remove(); map.remove();
expect(spy).toHaveBeenCalled(); expect(spy.called).to.be.ok();
}); });
it("fires no unload event if not loaded", function () { it("fires no unload event if not loaded", function () {
var container = document.createElement('div'), var container = document.createElement('div'),
map = new L.Map(container); map = new L.Map(container),
spy = sinon.spy();
map.on('unload', spy); map.on('unload', spy);
map.remove(); map.remove();
expect(spy).not.toHaveBeenCalled(); expect(spy.called).not.to.be.ok();
}); });
it("undefines container._leaflet", function () { it("undefines container._leaflet", function () {
var container = document.createElement('div'), var container = document.createElement('div'),
map = new L.Map(container); map = new L.Map(container);
map.remove(); map.remove();
expect(container._leaflet).toBeUndefined(); expect(container._leaflet).to.be(undefined);
}); });
it("unbinds events", function () { it("unbinds events", function () {
var container = document.createElement('div'), var container = document.createElement('div'),
map = new L.Map(container).setView([0, 0], 1); map = new L.Map(container).setView([0, 0], 1),
spy = sinon.spy();
map.on('click dblclick mousedown mouseup mousemove', spy); map.on('click dblclick mousedown mouseup mousemove', spy);
map.remove(); map.remove();
happen.click(container); happen.click(container);
@ -40,7 +42,7 @@ describe("Map", function () {
happen.mousedown(container); happen.mousedown(container);
happen.mouseup(container); happen.mouseup(container);
happen.mousemove(container); happen.mousemove(container);
expect(spy).not.toHaveBeenCalled(); expect(spy.called).to.not.be.ok();
}); });
}); });
@ -48,36 +50,38 @@ describe("Map", function () {
it ('throws if not set before', function () { it ('throws if not set before', function () {
expect(function () { expect(function () {
map.getCenter(); map.getCenter();
}).toThrow(); }).to.throwError();
}); });
}); });
describe("#whenReady", function () { describe("#whenReady", function () {
describe("when the map has not yet been loaded", function () { describe("when the map has not yet been loaded", function () {
it("calls the callback when the map is loaded", function () { it("calls the callback when the map is loaded", function () {
var spy = sinon.spy();
map.whenReady(spy); map.whenReady(spy);
expect(spy).not.toHaveBeenCalled(); expect(spy.called).to.not.be.ok();
map.setView([0, 0], 1); map.setView([0, 0], 1);
expect(spy).toHaveBeenCalled(); expect(spy.called).to.be.ok();
}); });
}); });
describe("when the map has already been loaded", function () { describe("when the map has already been loaded", function () {
it("calls the callback immediately", function () { it("calls the callback immediately", function () {
var spy = sinon.spy();
map.setView([0, 0], 1); map.setView([0, 0], 1);
map.whenReady(spy); map.whenReady(spy);
expect(spy).toHaveBeenCalled(); expect(spy.called).to.be.ok();
}); });
}); });
}); });
describe("#setView", function () { describe("#setView", function () {
it("sets the view of the map", function () { it("sets the view of the map", function () {
expect(map.setView([51.505, -0.09], 13)).toBe(map); expect(map.setView([51.505, -0.09], 13)).to.be(map);
expect(map.getZoom()).toBe(13); expect(map.getZoom()).to.be(13);
expect(map.getCenter().distanceTo([51.505, -0.09])).toBeLessThan(5); expect(map.getCenter().distanceTo([51.505, -0.09])).to.be.lessThan(5);
}); });
}); });
@ -97,40 +101,43 @@ describe("Map", function () {
map = L.map(c, { minZoom: 5, maxZoom: 10 }); map = L.map(c, { minZoom: 5, maxZoom: 10 });
L.tileLayer("{z}{x}{y}", { minZoom:0, maxZoom: 10 }).addTo(map); L.tileLayer("{z}{x}{y}", { minZoom:0, maxZoom: 10 }).addTo(map);
L.tileLayer("{z}{x}{y}", { minZoom:5, maxZoom: 15 }).addTo(map); L.tileLayer("{z}{x}{y}", { minZoom:5, maxZoom: 15 }).addTo(map);
expect(map.getMinZoom()).toBe(5); expect(map.getMinZoom()).to.be(5);
expect(map.getMaxZoom()).toBe(10); expect(map.getMaxZoom()).to.be(10);
}); });
}); });
describe("#addLayer", function () { describe("#addLayer", function () {
describe("When the first layer is added to a map", function () { describe("When the first layer is added to a map", function () {
it("fires a zoomlevelschange event", function () { it("fires a zoomlevelschange event", function () {
var spy = sinon.spy();
map.on("zoomlevelschange", spy); map.on("zoomlevelschange", spy);
expect(spy).not.toHaveBeenCalled(); expect(spy.called).not.to.be.ok();
L.tileLayer("{z}{x}{y}", { minZoom:0, maxZoom: 10 }).addTo(map); L.tileLayer("{z}{x}{y}", { minZoom:0, maxZoom: 10 }).addTo(map);
expect(spy).toHaveBeenCalled(); expect(spy.called).to.be.ok();
}); });
}); });
describe("when a new layer with greater zoomlevel coverage than the current layer is added to a map", function () { describe("when a new layer with greater zoomlevel coverage than the current layer is added to a map", function () {
it("fires a zoomlevelschange event", function () { it("fires a zoomlevelschange event", function () {
var spy = sinon.spy();
L.tileLayer("{z}{x}{y}", { minZoom:0, maxZoom: 10 }).addTo(map); L.tileLayer("{z}{x}{y}", { minZoom:0, maxZoom: 10 }).addTo(map);
map.on("zoomlevelschange", spy); map.on("zoomlevelschange", spy);
expect(spy).not.toHaveBeenCalled(); expect(spy.called).not.to.be.ok();
L.tileLayer("{z}{x}{y}", { minZoom:0, maxZoom: 15 }).addTo(map); L.tileLayer("{z}{x}{y}", { minZoom:0, maxZoom: 15 }).addTo(map);
expect(spy).toHaveBeenCalled(); expect(spy.called).to.be.ok();
}); });
}); });
describe("when a new layer with the same or lower zoomlevel coverage as the current layer is added to a map", function () { describe("when a new layer with the same or lower zoomlevel coverage as the current layer is added to a map", function () {
it("fires no zoomlevelschange event", function () { it("fires no zoomlevelschange event", function () {
var spy = sinon.spy();
L.tileLayer("{z}{x}{y}", { minZoom:0, maxZoom: 10 }).addTo(map); L.tileLayer("{z}{x}{y}", { minZoom:0, maxZoom: 10 }).addTo(map);
map.on("zoomlevelschange", spy); map.on("zoomlevelschange", spy);
expect(spy).not.toHaveBeenCalled(); expect(spy.called).not.to.be.ok();
L.tileLayer("{z}{x}{y}", { minZoom:0, maxZoom: 10 }).addTo(map); L.tileLayer("{z}{x}{y}", { minZoom:0, maxZoom: 10 }).addTo(map);
expect(spy).not.toHaveBeenCalled(); expect(spy.called).not.to.be.ok();
L.tileLayer("{z}{x}{y}", { minZoom:0, maxZoom: 5 }).addTo(map); L.tileLayer("{z}{x}{y}", { minZoom:0, maxZoom: 5 }).addTo(map);
expect(spy).not.toHaveBeenCalled(); expect(spy.called).not.to.be.ok();
}); });
}); });
}); });
@ -139,12 +146,13 @@ describe("Map", function () {
describe("when the last tile layer on a map is removed", function () { describe("when the last tile layer on a map is removed", function () {
it("fires a zoomlevelschange event", function () { it("fires a zoomlevelschange event", function () {
map.whenReady(function(){ map.whenReady(function(){
var spy = sinon.spy();
var tl = L.tileLayer("{z}{x}{y}", { minZoom:0, maxZoom: 10 }).addTo(map); var tl = L.tileLayer("{z}{x}{y}", { minZoom:0, maxZoom: 10 }).addTo(map);
map.on("zoomlevelschange", spy); map.on("zoomlevelschange", spy);
expect(spy).not.toHaveBeenCalled(); expect(spy.called).not.to.be.ok();
map.removeLayer(tl); map.removeLayer(tl);
expect(spy).toHaveBeenCalled(); expect(spy.called).to.be.ok();
}); });
}); });
}); });
@ -152,13 +160,14 @@ describe("Map", function () {
describe("when a tile layer is removed from a map and it had greater zoom level coverage than the remainding layer", function () { describe("when a tile layer is removed from a map and it had greater zoom level coverage than the remainding layer", function () {
it("fires a zoomlevelschange event", function () { it("fires a zoomlevelschange event", function () {
map.whenReady(function(){ map.whenReady(function(){
var tl = L.tileLayer("{z}{x}{y}", { minZoom:0, maxZoom: 10 }).addTo(map), var spy = sinon.spy(),
tl = L.tileLayer("{z}{x}{y}", { minZoom:0, maxZoom: 10 }).addTo(map),
t2 = L.tileLayer("{z}{x}{y}", { minZoom:0, maxZoom: 15 }).addTo(map); t2 = L.tileLayer("{z}{x}{y}", { minZoom:0, maxZoom: 15 }).addTo(map);
map.on("zoomlevelschange", spy); map.on("zoomlevelschange", spy);
expect(spy).not.toHaveBeenCalled(); expect(spy.called).to.not.be.ok();
map.removeLayer(t2); map.removeLayer(t2);
expect(spy).toHaveBeenCalled(); expect(spy.called).to.be.ok();
}); });
}); });
}); });
@ -183,26 +192,28 @@ describe("Map", function () {
describe("#eachLayer", function () { describe("#eachLayer", function () {
it("returns self", function () { it("returns self", function () {
expect(map.eachLayer(function () {})).toBe(map); expect(map.eachLayer(function () {})).to.be(map);
}); });
it("calls the provided function for each layer", function () { it("calls the provided function for each layer", function () {
var t1 = L.tileLayer("{z}{x}{y}").addTo(map), var t1 = L.tileLayer("{z}{x}{y}").addTo(map),
t2 = L.tileLayer("{z}{x}{y}").addTo(map); t2 = L.tileLayer("{z}{x}{y}").addTo(map),
spy = sinon.spy();
map.eachLayer(spy); map.eachLayer(spy);
expect(spy.calls.length).toEqual(2); expect(spy.callCount).to.eql(2);
expect(spy.calls[0].args).toEqual([t1]); expect(spy.firstCall.args).to.eql([t1]);
expect(spy.calls[1].args).toEqual([t2]); expect(spy.secondCall.args).to.eql([t2]);
}); });
it("calls the provided function with the provided context", function () { it("calls the provided function with the provided context", function () {
var t1 = L.tileLayer("{z}{x}{y}").addTo(map); var t1 = L.tileLayer("{z}{x}{y}").addTo(map),
spy = sinon.spy();
map.eachLayer(spy, map); map.eachLayer(spy, map);
expect(spy.calls[0].object).toEqual(map); expect(spy.thisValues[0]).to.eql(map);
}); });
}); });
}); });