2016-04-14 10 views
2

Merhaba bu direktif var dönmek benim test kodu:Açısal Karma element.isolateScope çağırarak, izole kapsam ve controllerAs ile Direktifi() tanımsız

describe('when correctly configured', function() { 
    let scope, element, is; 

    beforeEach(inject(function ($compile, $rootScope) { 
    scope = $rootScope.$new(); 

    scope.config = { 
     columns: [ 
     { 
      label: 'Label 1', 
      prop: 'label-1' 
     }, 
     { 
      label: 'Label 2', 
      prop: 'label-2' 
     } 
     ] 
    }; 

    scope.data = [ 
     { 
     'label-1': 'Sample 1.1', 
     'label-2': 'Sample 1.2' 
     }, 
     { 
     'label-1': 'Sample 2.1', 
     'label-2': 'Sample 2.2' 
     } 
    ] 

    element = angular.element('<xos-table config="config" data="data"></xos-table>'); 
    $compile(element)(scope); 
    is = element.isolateScope(); 
    scope.$digest(); 

    })); 

    it('should contain 2 columns', function() { 
    expect(is.columns).toEqual(2); 
    }); 
}); 

Bu aynı setup bir çok kez ettik, benim direktifin isolateScope erişemez neden üzerinde herhangi bir fikir? Eğer testte üç hatalar yaptık http://plnkr.co/edit/JYYtck?p=preview

cevap

1

: Burada

kodu ve testi ile bir Plunker size (ayrı yüklenen oluyor yönergesini içeren modülü yüklemek vermedi

  1. tarif blok). Bu nedenle isolateScope tanımsızdır;
  2. scope.columns yerine scope.vm.columns;
  3. Sen 2'ye sütunlar dizisi kıyasla yerine fixed plunkr İşte 2.

için uzunluğunu karşılaştırma.

Özü:

beforeEach(module('xos.uiComponents.table')); 

[...] 

it('should contain 2 columns', function() { 
    console.log('aaa', iso); 

    // one is the filter, the other two are the products, one is the pagination 
    expect(iso.vm.columns.length).toEqual(2); 
}); 
İlgili konular