我有一个 Angular 应用程序(从 ASP.NET MVC 项目运行。)

在此应用程序中,我有一个具有以下链接功能的指令:

    link: function (scope, element, attrs, formCtrl) {
        element.bind('click', function (event) {
            formCtrl.$setPristine();
        });

    }

我写了这个测试:

var $compile,
        $rootScope,
        form;

    beforeEach(module('points'));

    beforeEach(inject(function(_$compile_, _$rootScope_, testHelper){
        $compile = _$compile_;
        $rootScope = _$rootScope_;
        testHelper.expectBaseRoute();
    }));

    it('Should set form to pristine when clicked', function () {
        var scope = $rootScope;

        form = $compile('<form name="testForm" unsaved-warning-clear><input name="test" ng-model="value"/></form>')(scope);
        scope.value = "abc";
        scope.$digest();

        scope.testForm.test.$setViewValue('def');

        expect(scope.testForm.$pristine).toBe(false);

        $(form).trigger('click');

        expect(scope.testForm.$pristine).toBe(true);
    });

如果我使用 Jasmine 在浏览器中运行它,测试就会通过。

如果我运行它 chutzpah 在ide内部,它失败了。它永远不会触发 click 事件。

我有什么遗漏的吗?

有帮助吗?

解决方案

就我而言,这是一次愚蠢的用户错误事件。

从浏览器运行的我的 Jasmine 测试运行程序文件有 jquery,然后是角度引用。

我的 chutzpah.json 文件的顺序相反。

我将 jquery 参考向上移动,它开始工作。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top