首页 > 解决方案 > 茉莉花的功能范围单元测试

问题描述

我对 Angular 和单元测试很陌生,但我需要为我的应用程序做一些事情。我需要的只是一些关于如何做的指导。

下面是我需要测试的代码

var app = angular.module('quizApp', []);

app.directive('quiz', function(quizFactory) {
    return {
        restrict: 'AE',
        scope: {},
        templateUrl: 'template.html',
        link: function(scope, elem, attrs) {
            scope.start = function() {
                scope.id = 0;
                scope.quizOver = false;
                scope.inProgress = true;
                scope.getQuestion();
            };

            scope.reset = function() {
                scope.inProgress = false;
                scope.score = 0;
            }

这是我迄今为止一直在测试的。

describe('$scope.start', function() {
        it('Should start the quiz as long as start button is pressed', function() {
            $scope.id = 0;
            $scope.quizOver = false;
            $scope.inProgress = true;

            expect(0).toBe(0);
            expect(false).not.toBe(true);
            expect(true).toBe(true);
    });
});

我的测试不起作用,因为我遇到了错误。有谁可以告诉我如何正确地做到这一点?非常感谢

标签: angularjsjasmine

解决方案


推荐阅读