From fb3a7db0809b959d50be4cb93a65a91200071dd5 Mon Sep 17 00:00:00 2001 From: Matias Niemelä Date: Wed, 21 Aug 2013 21:29:40 -0400 Subject: feat(ngMock): add support for creating dynamic style sheets within test code --- test/ngAnimate/animateSpec.js | 12 ++++++++---- test/privateMocksSpec.js | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 4 deletions(-) create mode 100644 test/privateMocksSpec.js (limited to 'test') diff --git a/test/ngAnimate/animateSpec.js b/test/ngAnimate/animateSpec.js index 30bf6ba7..37026640 100644 --- a/test/ngAnimate/animateSpec.js +++ b/test/ngAnimate/animateSpec.js @@ -1118,11 +1118,15 @@ describe("ngAnimate", function() { })); it("should properly execute CSS animations/transitions and use callbacks when using addClass / removeClass", - inject(function($animate, $rootScope, $sniffer, $rootElement, $timeout) { + inject(function($animate, $rootScope, $sniffer, $rootElement, $timeout, $window, $document) { - var transition = 'transition:11s linear all;'; - var style = transition + ' ' + vendorPrefix + transition; - var parent = jqLite('
'); + var ss = createMockStyleSheet($document, $window); + ss.addRule('.klass-add', 'transition:11s linear all'); + ss.addRule('.klass-add', vendorPrefix + 'transition:11s linear all'); + ss.addRule('.klass-remove', 'transition:11s linear all'); + ss.addRule('.klass-remove', vendorPrefix + 'transition:11s linear all'); + + var parent = jqLite('
'); $rootElement.append(parent); body.append($rootElement); var element = jqLite(parent.find('span')); diff --git a/test/privateMocksSpec.js b/test/privateMocksSpec.js new file mode 100644 index 00000000..e58a2b75 --- /dev/null +++ b/test/privateMocksSpec.js @@ -0,0 +1,36 @@ +describe('private mocks', function() { + describe('createMockStyleSheet', function() { + + it('should allow custom styles to be created and removed when the stylesheet is destroyed', + inject(function($compile, $document, $window, $rootElement, $rootScope) { + + var doc = $document[0]; + var count = doc.styleSheets.length; + var stylesheet = createMockStyleSheet($document, $window); + expect(doc.styleSheets.length).toBe(count + 1); + + jqLite(doc.body).append($rootElement); + + var elm = $compile('
...
')($rootScope); + $rootElement.append(elm); + + expect(getStyle(elm, 'paddingTop')).toBe('0px'); + + stylesheet.addRule('.padded', 'padding-top:2px'); + + expect(getStyle(elm, 'paddingTop')).toBe('2px'); + + stylesheet.destroy(); + + expect(getStyle(elm, 'paddingTop')).toBe('0px'); + + function getStyle(element, key) { + var node = element[0]; + return node.currentStyle ? + node.currentStyle[key] : + $window.getComputedStyle(node)[key]; + }; + })); + + }); +}); -- cgit v1.2.3