2

有没有办法“取消初始化”已经被 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'
4

1 回答 1

2

好像设置:

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

在每次测试之前都可以解决问题。

于 2013-03-13T21:42:19.927 回答