jQuery Mobile:我可以“取消初始化”页面吗?

时间:2013-03-13 20:30:26

标签: jquery testing jquery-mobile

有没有办法“取消初始化”由jQuery Mobile初始化的页面?我在一个页面上运行整个测试套件,并希望在每次测试后清理JQM。它目前设置如下:

before(function () {
    $.mobile.ajaxEnabled = false;
    $.mobile.linkBindingEnabled = false;
    $.mobile.hashListeningEnabled = false;
    $.mobile.pushStateEnabled = false;
    $.mobile.changePage.defaults.changeHash = false;
    $.mobile.autoInitializePage = false;
    $.mobile.defaultPageTransition = 'slide';

    this.$el = $('<div></div>');
    $(document.body).append(this.$el);
});

after(function () {
    this.$el.remove();
});

afterEach(function () {
    this.$el.empty();
});

it('some test', function () {
    var page = $('<div data-role="page">...</div>')
    this.$el.append(page);

    // Each test will perform calls like these at some point
    $.mobile.initializePage();
    $.mobile.changePage(page, {
        allowSamePageTransition: true,
        pageContainer: this.$el,
        transition: 'none'
    });

    assert_whatever();
});

第一个测试运行正常但是当第二个测试运行时我得到错误:

cannot call methods on loader prior to initialization; attempted to call method 'show'

1 个答案:

答案 0 :(得分:2)

似乎设置:

$.mobile.activePage = undefined;
$.mobile.loaderWidget = undefined;

在每次测试之前完成这个技巧。