salix/client/core/src/directives/specs/id.spec.js

45 lines
1.3 KiB
JavaScript
Raw Normal View History

2017-10-24 05:57:25 +00:00
describe('Directive vnId', () => {
let $scope;
let $element;
let compile;
beforeEach(() => {
angular.mock.module('client');
});
compile = _element => {
2018-01-30 13:48:21 +00:00
inject(($compile, $rootScope, _$httpBackend_) => {
2017-10-24 05:57:25 +00:00
$scope = $rootScope.$new();
2018-01-30 13:48:21 +00:00
_$httpBackend_.when('GET', /\/locale\/\w+\/[a-z]{2}\.json/).respond({});
2017-10-24 05:57:25 +00:00
$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(() => {
2017-10-24 05:57:25 +00:00
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(() => {
2017-10-24 05:57:25 +00:00
compile(html);
}).toThrow(new Error(`vnId: Can't find controller for element '1'`));
});
it(`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();
});
2017-10-24 05:57:25 +00:00
});