Grunt使用记录 三

dom测试

dom测试的配置,在搞这个时候,费了点劲,但是真正配置起来超简单。

require

由于用了jasmine,所以就需要有与jasmine配套的,本想找个仅仅依赖jasmine的库,但失败了,就配了个依赖jquery的。

jquery-1.11.0.js
jasmine-jquery.js
jasmine-ajax.js //ajax模拟

配置

Gruntfile.js

jasmine: {
            defualt: {
                src: 'pub/*.js',
                options: {
                    vendor: [//在vendor里添加测试所依赖的库即可
                        "libs/jquery-1.11.0.js",
                        "libs/jasmine-jquery.js",
                        "libs/jasmine-ajax.js"
                    ],
                    specs: 'test/*Spec.js'
                }
            }
        }
代码样例
describe("bind", function() {
    // jasmine.getFixtures().fixturesPath = "test/fixtures/";//设定存放测试html的文件夹
    var fixture, bind;
    var Bind = bindProvider();//自己封装的东西
    beforeEach(function() {
        fixture = setFixtures('<div id="bind">foo</div>');
        bind = new Bind(fixture);
        bind.bind("aa", "bbb");
    });
    it("should bind key/value to the dom", function() {
        //var div = setFixtures('<div class="post">foo</div>');
        // var bind = new Bind(fixture);
        //bind.bind("aa", "bbb");
        expect(bind.hasBind("aa")).toBe(true);
    });
    it("can get the binded thing", function() {
        expect(bind.get("aa")).toEqual("bbb");
    });
    it("can unbind", function() {
        bind.unbind("aa");
        expect(bind.hasBind("aa")).toBe(false);
    });
});
后记

具体测试api,可参见jasmine-jqueryjasmine-ajax,都蛮简单的,不做细说。


转载于:https://my.oschina.net/myprogworld/blog/227399

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值