index-spec.js 1.29 KB
var expect = require('expect.js');
//var yasJssdk = require('../yas');

//工具库
var util = require('../src/util');

//cookie处理
var cookies = require('../src/cookie');

//跨域通信
var cross = require('../src/cross');

//事件处理
var ev = require('../src/event');

var config = require('../src/config');


describe('yas-jssdk', function() {

  it('cookies 测试', function() {
     cookies('a','1',{path:"/",domain:config.yasDomain,expires:365*200});
     expect(cookies('a')).to.equal('1');
     cookies('a',null,{path:"/",domain:config.yasDomain,expires:365*200});
     expect(cookies('a')).to.equal(null);
  });

  it('util 测试', function() {
     var ret = util.merge({a:1},{b:2});
     expect(ret.a).to.equal(1);
     expect(ret.b).to.equal(2);
     var url = util.genParam(ret);
     expect(url).to.equal('a=1&b=2');
     var string = util.trim('   fsdf fsdf fdsf   ');
     expect(string).to.equal('fsdf fsdf fdsf');
     var a = util.hashClientInfo();
     var b = util.hashClientInfo();
     expect(a).to.be(b);
  });

  it('ev 测试',function()
  {
     var i=0;
     function add()
     {
       i=2;
     }
     ev.addEventHandler(document,'load',add);

     window.setTimeout(function()
     {
		expect(i).to.be(2);
     },1000);

     ev.removeEventHandler(document,'load',add);
  });

});