Sha256: f6cd8d545a52b0353801fd8b764eb5c06dd35a085dfc6c178e54c098e9a623fa

Contents?: true

Size: 1.66 KB

Versions: 8

Compression:

Stored size: 1.66 KB

Contents

describe('ui-if', function () {
  var scope, $compile, elm;

  beforeEach(module('ui.directives'));
  beforeEach(inject(function ($rootScope, _$compile_) {
    scope = $rootScope.$new();
    $compile = _$compile_;
    elm = $('<div>');
  }));

  function makeIf(expr) {
    elm.append($compile('<div ui-if="' + expr + '"><div>Hi</div></div>')(scope));
    scope.$apply();
  }

  it('should immediately remove element if condition is false', function () {
    makeIf('false');
    expect(elm.children().length).toBe(0);
  });

  it('should leave the element if condition is true', function () {
    makeIf('true');
    expect(elm.children().length).toBe(1);
  });

  it('should create then remove the element if condition changes', function () {
    scope.hello = true;
    makeIf('hello');
    expect(elm.children().length).toBe(1);
    scope.$apply('hello = false');
    expect(elm.children().length).toBe(0);
  });

  it('should create a new scope', function () {
    scope.$apply('value = true');
    elm.append($compile(
      '<div ui-if="value"><span ng-init="value=false"></span></div>'
    )(scope));
    scope.$apply();
    expect(elm.children('div').length).toBe(1);
  });

  it('should play nice with other elements beside it', function () {
    scope.values = [1, 2, 3, 4];
    elm.append($compile(
      '<div ng-repeat="i in values"></div>' +
        '<div ui-if="values.length==4"></div>' +
        '<div ng-repeat="i in values"></div>'
    )(scope));
    scope.$apply();
    expect(elm.children().length).toBe(9);
    scope.$apply('values.splice(0,1)');
    expect(elm.children().length).toBe(6);
    scope.$apply('values.push(1)');
    expect(elm.children().length).toBe(9);
  });
});

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
active_record_survey_api-0.0.19 spec/test_app/vendor/assets/bower_components/angular-ui/modules/directives/if/test/ifSpec.js
active_record_survey_api-0.0.18 spec/test_app/vendor/assets/bower_components/angular-ui/modules/directives/if/test/ifSpec.js
active_record_survey_api-0.0.17 spec/test_app/vendor/assets/bower_components/angular-ui/modules/directives/if/test/ifSpec.js
active_record_survey_api-0.0.14 spec/test_app/vendor/assets/bower_components/angular-ui/modules/directives/if/test/ifSpec.js
active_record_survey_api-0.0.12 spec/test_app/vendor/assets/bower_components/angular-ui/modules/directives/if/test/ifSpec.js
active_record_survey_api-0.0.11 spec/test_app/vendor/assets/bower_components/angular-ui/modules/directives/if/test/ifSpec.js
active_record_survey_api-0.0.7 spec/test_app/vendor/assets/bower_components/angular-ui/modules/directives/if/test/ifSpec.js
active_record_survey_api-0.0.6 spec/test_app/vendor/assets/bower_components/angular-ui/modules/directives/if/test/ifSpec.js