mirror of
https://github.com/FoggedLens/iD.git
synced 2026-02-14 01:33:03 +00:00
46 lines
1.7 KiB
JavaScript
46 lines
1.7 KiB
JavaScript
describe('iD.Util', function() {
|
|
it('#tagText', function() {
|
|
expect(iD.util.tagText({})).to.eql('');
|
|
expect(iD.util.tagText({tags:{foo:'bar'}})).to.eql('foo=bar');
|
|
expect(iD.util.tagText({tags:{foo:'bar',two:'three'}})).to.eql('foo=bar, two=three');
|
|
});
|
|
|
|
it('#stringQs', function() {
|
|
expect(iD.util.stringQs('foo=bar')).to.eql({foo: 'bar'});
|
|
expect(iD.util.stringQs('foo=bar&one=2')).to.eql({foo: 'bar', one: '2' });
|
|
expect(iD.util.stringQs('')).to.eql({});
|
|
});
|
|
|
|
it('#qsString', function() {
|
|
expect(iD.util.qsString({ foo: 'bar' })).to.eql('foo=bar');
|
|
expect(iD.util.qsString({ foo: 'bar', one: 2 })).to.eql('foo=bar&one=2');
|
|
expect(iD.util.qsString({})).to.eql('');
|
|
});
|
|
|
|
it('#getPrototypeOf', function() {
|
|
var a = function() {};
|
|
a.prototype = { foo: 'foo' };
|
|
expect(iD.util.getPrototypeOf({})).to.eql({});
|
|
expect(iD.util.getPrototypeOf(new a())).to.eql({ foo: 'foo' });
|
|
});
|
|
|
|
describe('#asyncMap', function() {
|
|
it('handles correct replies', function() {
|
|
iD.util.asyncMap([1, 2, 3],
|
|
function(d, c) { c(null, d * 2); },
|
|
function(err, res) {
|
|
expect(err).to.eql([null, null, null]);
|
|
expect(res).to.eql([2, 4, 6]);
|
|
});
|
|
});
|
|
it('handles errors', function() {
|
|
iD.util.asyncMap([1, 2, 3],
|
|
function(d, c) { c('whoops ' + d, null); },
|
|
function(err, res) {
|
|
expect(err).to.eql(['whoops 1', 'whoops 2', 'whoops 3']);
|
|
expect(res).to.eql([null, null, null]);
|
|
});
|
|
});
|
|
});
|
|
});
|