Created
September 29, 2016 19:43
-
-
Save lolptdr/e81c55f5a8c72a35f0367f081a08e3cc to your computer and use it in GitHub Desktop.
Created new spec file for Joel's phonebook directive
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
directiveTest({ | |
module: angular.module('app'), | |
name: 'phonebookDirectve', | |
template: '<phonebook phone-numbers="testNumbers"></phonebook>', | |
controller: 'phonebook', | |
selectors: { | |
'phonenumber': 0 | |
}, | |
assertions: { | |
'should expose refresh functionality': function($element) { | |
expect($element.isolateScope().refresh).toBeDefined(); | |
}, | |
'should delegate refresh functionality to phone model': function(phoneModel, $q, $element, $scope) { | |
var myTestNumbers = ['5125328228']; | |
spyOn(phoneModel, 'get').and.returnValue($q.resolve(myTestNumbers)); | |
$element.isolateScope().refresh(); | |
$scope.$apply(); | |
expect($scope.testNumbers).toEqual(myTestNumbers); | |
expect($element.isolateScope().phoneNumbers).toEqual(myTestNumbers); | |
} | |
} | |
}); | |
describe('Directive: phonebook', function () { | |
beforeEach(module('app')); | |
beforeEach(inject(function($compile, $rootScope, phoneModel, $q) { | |
var template = '<phonebook phone-numbers="testNumbers"></phonebook>'; | |
this.$parentScope = $rootScope.$new(); | |
this.phoneModel = phoneModel; | |
this.$element = $compile(template)(this.$parentScope); | |
$rootScope.$apply(); | |
this.$isolateScope = this.$element.isolateScope(); | |
})); | |
it('should exist', function() { | |
expect(this.$element).toBeDefined(); | |
}); | |
it('should contain the controller', function() { | |
expect(this.$element.controller('phonebook')).toBeDefined(); | |
}); | |
it('should expose refresh functionality', function() { | |
expect(this.$isolateScope.refresh).toBeDefined(); | |
}); | |
it('should delegate refresh functionality to phone model', inject(function($q) { | |
var myTestNumbers = ['5125328228']; | |
spyOn(this.phoneModel, 'get').and.returnValue($q.resolve(myTestNumbers)); | |
this.$isolateScope.refresh(); | |
this.$parentScope.$apply(); | |
// expect(this.$isolateScope.refresh).toBeDefined(); | |
expect(this.$parentScope.testNumbers).toEqual(myTestNumbers); //parentScope | |
expect(this.$isolateScope.phoneNumbers).toEqual(myTestNumbers); | |
})); | |
it('should show the numbers in the template', function() { | |
this.$parentScope.testNumbers = ['1', '2', '3']; | |
this.$parentScope.$apply(); | |
expect(this.$element.find('phonenumber').length).toBe(this.$parentScope.testNumbers.length); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment