如何在业力中模拟$ window.location.href

时间:2018-07-12 15:51:47

标签: javascript angularjs karma-jasmine

我具有此功能,基本上只是使用新的参数值重新加载网址

(function() {
    classOpt.factory('classService', function() {
        return {
            classChanged : function(desc) {
                var url = new URL(window.location.href);
                var replaceUrl = url.searchParams.set("classDesc", desc);
                window.location.href = replaceUrl;

在我的测试中,我收到此错误

undefined is not an object (evaluating 'url.searchParams.set')

这是可以预期的,因为Jasmine仍然使用运行Karma的本地主机URL。因此,如果我想模拟window.location.href以便拥有不同的网址,该怎么办?任何帮助表示赞赏。

0 个答案:

没有答案