Leaflet/spec/suites/core/UtilSpec.js

105 lines
2.0 KiB
JavaScript
Raw Normal View History

2010-09-07 00:14:04 +08:00
describe('Util', function() {
2010-09-02 21:14:25 +08:00
describe('#extend', function() {
var a;
beforeEach(function() {
a = {
foo: 5,
bar: 'asd'
};
});
it('should extend the first argument with the properties of the second', function() {
L.Util.extend(a, {
bar: 7,
baz: 3
});
expect(a).toEqual({
foo: 5,
bar: 7,
baz: 3
});
});
it('should work with more than 2 arguments', function() {
L.Util.extend(a, {bar: 7}, {baz: 3});
expect(a).toEqual({
foo: 5,
bar: 7,
baz: 3
});
});
});
describe('#bind', function() {
it('should return the given function with the given context', function() {
var fn = function() {
return this;
};
var fn2 = L.Util.bind(fn, 5);
expect(fn2()).toEqual(5);
});
});
2010-09-06 21:17:06 +08:00
describe('#stamp', function() {
it('should set a unique id on the given object and return it', function() {
var a = {},
id = L.Util.stamp(a);
expect(typeof id).toEqual('number');
expect(L.Util.stamp(a)).toEqual(id);
2010-09-06 21:17:06 +08:00
var b = {},
id2 = L.Util.stamp(b);
expect(id2).not.toEqual(id);
});
});
2012-07-05 17:54:40 +08:00
describe('#getParamString', function() {
it('should create a valid query string for appending depending on url input', function() {
var a = {
2012-12-27 00:45:38 +08:00
url: "http://example.com/get",
obj: {bar: 7, baz: 3},
result: "?bar=7&baz=3"
2012-12-23 12:52:25 +08:00
};
expect(L.Util.getParamString(a.obj,a.url)).toEqual(a.result);
var b = {
2012-12-27 00:45:38 +08:00
url: "http://example.com/get?justone=qs",
obj: {bar: 7, baz: 3},
result: "&bar=7&baz=3"
2012-12-23 12:52:25 +08:00
};
expect(L.Util.getParamString(b.obj,b.url)).toEqual(b.result);
2012-12-28 03:39:19 +08:00
var c = {
url: undefined,
obj: {bar: 7, baz: 3},
result: "?bar=7&baz=3"
};
expect(L.Util.getParamString(c.obj,c.url)).toEqual(c.result);
});
});
2012-07-05 17:54:40 +08:00
// TODO cancel/requestAnimFrame?
// TODO limitExecByInterval
// TODO formatNum
// TODO splitWords
// TODO setOptions
// TODO template
2012-12-27 00:45:38 +08:00
});