salix/front/core/directives/specs/id.spec.js

44 lines
1.2 KiB
JavaScript

describe('Directive vnId', () => {
let $scope;
let $element;
let compile;
beforeEach(ngModule('vnCore'));
compile = _element => {
inject(($compile, $rootScope) => {
$scope = $rootScope.$new();
$element = angular.element(_element);
$compile($element)($scope);
$scope.$digest();
});
};
it(`should throw an error when there's no id defined`, () => {
let html = `<form vn-id=""></form>`;
expect(() => {
compile(html);
}).toThrow(new Error(`vnId: Attribute can't be null`));
});
it(`should throw an error when these's no controller defined in $element[0]`, () => {
let html = `<div vn-id="1"></div>`;
expect(() => {
compile(html);
}).toThrow(new Error(`vnId: Can't find controller for element '1'`));
});
// FIXME: Sometimes fails with '$scope is undefined'
xit(`should set the controller into the $scope as there are no errors being thrown`, () => {
let html = `<form vn-id="1"></form>`;
expect($scope['1']).not.toBeDefined();
compile(html);
expect($scope['1']).toBeDefined();
});
});