aboutsummaryrefslogtreecommitdiffstats
path: root/test/privateMocksSpec.js
diff options
context:
space:
mode:
authorMatias Niemelä2013-08-21 21:29:40 -0400
committerMisko Hevery2013-08-23 14:04:35 -0700
commitfb3a7db0809b959d50be4cb93a65a91200071dd5 (patch)
tree8179dc125231880b7b48b64d5bcf1cf0d14d1cba /test/privateMocksSpec.js
parent040aa11ceb510d8f8ec8349a3ca99d9db874daf0 (diff)
downloadangular.js-fb3a7db0809b959d50be4cb93a65a91200071dd5.tar.bz2
feat(ngMock): add support for creating dynamic style sheets within test code
Diffstat (limited to 'test/privateMocksSpec.js')
-rw-r--r--test/privateMocksSpec.js36
1 files changed, 36 insertions, 0 deletions
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('<div class="padded">...</div>')($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];
+ };
+ }));
+
+ });
+});