diff options
| author | Ken Sheedlo | 2013-07-12 17:42:27 -0700 |
|---|---|---|
| committer | Ken Sheedlo | 2013-07-24 10:42:20 -0700 |
| commit | 4a7b6a4555a76b19dd217171fc0ddce6707bca95 (patch) | |
| tree | 4646989291c1be2116c1e59c006f1208cb76c16a /docs/component-spec/errorDisplaySpec.js | |
| parent | dca23173e25a32cb740245ca7f7b01a84805f43f (diff) | |
| download | angular.js-4a7b6a4555a76b19dd217171fc0ddce6707bca95.tar.bz2 | |
docs(minErr): Build minErr doc site
Diffstat (limited to 'docs/component-spec/errorDisplaySpec.js')
| -rw-r--r-- | docs/component-spec/errorDisplaySpec.js | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/docs/component-spec/errorDisplaySpec.js b/docs/component-spec/errorDisplaySpec.js new file mode 100644 index 00000000..8122e253 --- /dev/null +++ b/docs/component-spec/errorDisplaySpec.js @@ -0,0 +1,68 @@ +describe("errorDisplay", function () { + + var $location, compileHTML; + + beforeEach(module('docsApp')); + + beforeEach(inject(function ($injector) { + var $rootScope = $injector.get('$rootScope'), + $compile = $injector.get('$compile'); + + $location = $injector.get('$location'); + + compileHTML = function (code) { + var elm = angular.element(code); + $compile(elm)($rootScope); + $rootScope.$digest(); + return elm; + }; + + this.addMatchers({ + toInterpolateTo: function (expected) { + // Given a compiled DOM node with a minerr-display attribute, + // assert that its interpolated string matches the expected text. + return this.actual.text() === expected; + } + }); + })); + + it('should interpolate a template with no parameters', function () { + var elm; + + spyOn($location, 'search').andReturn({}); + elm = compileHTML('<div error-display="This is a test"></div>'); + expect(elm).toInterpolateTo('This is a test'); + }); + + it('should interpolate a template with no parameters when search parameters are present', function () { + var elm; + + spyOn($location, 'search').andReturn({ p0: 'foobaz' }); + elm = compileHTML('<div error-display="This is a test"></div>'); + expect(elm).toInterpolateTo('This is a test'); + }); + + it('should correctly interpolate search parameters', function () { + var elm; + + spyOn($location, 'search').andReturn({ p0: '42' }); + elm = compileHTML('<div error-display="The answer is {0}"></div>'); + expect(elm).toInterpolateTo('The answer is 42'); + }); + + it('should interpolate parameters in the specified order', function () { + var elm; + + spyOn($location, 'search').andReturn({ p0: 'second', p1: 'first' }); + elm = compileHTML('<div error-display="{1} {0}"></div>'); + expect(elm).toInterpolateTo('first second'); + }); + + it('should preserve interpolation markers when fewer arguments than needed are provided', function () { + var elm; + + spyOn($location, 'search').andReturn({ p0: 'Fooooo' }); + elm = compileHTML('<div error-display="This {0} is {1} on {2}"></div>'); + expect(elm).toInterpolateTo('This Fooooo is {1} on {2}'); + }); +});
\ No newline at end of file |
