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 --- angularFiles.js | 3 ++- src/privateMocks.js | 28 ++++++++++++++++++++++++++++ test/ngAnimate/animateSpec.js | 12 ++++++++---- test/privateMocksSpec.js | 36 ++++++++++++++++++++++++++++++++++++ 4 files changed, 74 insertions(+), 5 deletions(-) create mode 100644 src/privateMocks.js create mode 100644 test/privateMocksSpec.js diff --git a/angularFiles.js b/angularFiles.js index a8509b3f..a20dc21a 100755 --- a/angularFiles.js +++ b/angularFiles.js @@ -79,7 +79,8 @@ angularFiles = { 'src/ngTouch/swipe.js', 'src/ngTouch/directive/ngClick.js', 'src/ngTouch/directive/ngSwipe.js', - 'docs/components/angular-bootstrap/bootstrap.js' + 'docs/components/angular-bootstrap/bootstrap.js', + 'src/privateMocks.js' ], 'angularScenario': [ diff --git a/src/privateMocks.js b/src/privateMocks.js new file mode 100644 index 00000000..6d9fb34f --- /dev/null +++ b/src/privateMocks.js @@ -0,0 +1,28 @@ +function createMockStyleSheet(doc, wind) { + doc = doc ? doc[0] : document; + wind = wind || window; + + var node = doc.createElement('style'); + var head = doc.getElementsByTagName('head')[0]; + head.appendChild(node); + + var ss = doc.styleSheets[doc.styleSheets.length - 1]; + + return { + addRule : function(selector, styles) { + try { + ss.insertRule(selector + '{ ' + styles + '}', 0); + } + catch(e) { + try { + ss.addRule(selector, styles); + } + catch(e) {} + } + }, + + destroy : function() { + head.removeChild(node); + } + }; +}; 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('