Unit test code improvements
This commit is contained in:
parent
e32762acfe
commit
2e0d5f2bde
|
@ -5,7 +5,7 @@ describe('Component vnAutocomplete', () => {
|
|||
|
||||
beforeEach(ngModule('vnCore'));
|
||||
|
||||
beforeEach(angular.mock.inject(($compile, $rootScope) => {
|
||||
beforeEach(inject(($compile, $rootScope) => {
|
||||
$element = $compile(`<vn-autocomplete></vn-autocomplete>`)($rootScope);
|
||||
$ctrl = $element.controller('vnAutocomplete');
|
||||
}));
|
||||
|
@ -45,26 +45,20 @@ describe('Component vnAutocomplete', () => {
|
|||
expect($ctrl.selection).toEqual(data);
|
||||
});
|
||||
|
||||
it(`should set selection to null when can't find an existing item in the data property`, () => {
|
||||
$ctrl.field = data.id;
|
||||
|
||||
expect($ctrl.selection).toEqual(null);
|
||||
});
|
||||
|
||||
it(`should perform a query if the item id isn't present in the data property`, inject($httpBackend => {
|
||||
$ctrl.url = '/TestModels';
|
||||
$ctrl.url = 'testUrl';
|
||||
|
||||
let filter = {
|
||||
fields: ['id', 'name'],
|
||||
where: {id: data.id}
|
||||
};
|
||||
let json = encodeURIComponent(JSON.stringify(filter));
|
||||
|
||||
$httpBackend.whenGET(`${$ctrl.url}?filter=${json}`).respond([data]);
|
||||
$httpBackend.whenGET(new RegExp(`testUrl.*`)).respond([data]);
|
||||
$ctrl.field = data.id;
|
||||
$httpBackend.flush();
|
||||
|
||||
expect($ctrl.selection).toEqual(data);
|
||||
}));
|
||||
|
||||
it(`should set selection to null when can't find an existing item in the data property`, () => {
|
||||
$ctrl.field = data.id;
|
||||
|
||||
expect($ctrl.selection).toEqual(null);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -7,7 +7,7 @@ window.inject = angular.mock.inject;
|
|||
|
||||
window.ngModule = function(moduleName) {
|
||||
return angular.mock.module(moduleName, function($provide, $translateProvider) {
|
||||
// To avoid unexpected request warnings caused by angular translate
|
||||
// Avoid unexpected request warnings caused by angular translate
|
||||
// https://angular-translate.github.io/docs/#/guide/22_unit-testing-with-angular-translate
|
||||
$provide.factory('customLocaleLoader', function($q) {
|
||||
return function() {
|
||||
|
|
Loading…
Reference in New Issue