diff --git a/test/helpers/matchers.js b/test/helpers/matchers.js index f345b15e5890..5d12f4f7de4f 100644 --- a/test/helpers/matchers.js +++ b/test/helpers/matchers.js @@ -131,25 +131,38 @@ beforeEach(function() { return { compare: function(actual) { if (arguments.length > 1) { - throw new Error('toHaveBeenCalledOnce does not take arguments, use toHaveBeenCalledWith'); + throw new Error('`toHaveBeenCalledOnce` does not take arguments, ' + + 'use `toHaveBeenCalledOnceWith`'); } if (!jasmine.isSpy(actual)) { throw new Error('Expected a spy, but got ' + jasmine.pp(actual) + '.'); } + var count = actual.calls.count(); + var pass = count === 1; + var message = function() { - var msg = 'Expected spy ' + actual.identity() + ' to have been called once, but was ', - count = this.actual.calls.count(); - return [ - count === 0 ? msg + 'never called.' : - msg + 'called ' + count + ' times.', - msg.replace('to have', 'not to have') + 'called once.' - ]; + var msg = 'Expected spy ' + actual.and.identity() + (pass ? ' not ' : ' ') + + 'to have been called once, but '; + + switch (count) { + case 0: + msg += 'it was never called.'; + break; + case 1: + msg += 'it was called once.'; + break; + default: + msg += 'it was called ' + count + ' times.'; + break; + } + + return msg; }; return { - pass: actual.calls.count() == 1, + pass: pass, message: message }; } @@ -158,43 +171,52 @@ beforeEach(function() { toHaveBeenCalledOnceWith: function(util, customEqualityTesters) { return { - compare: function(actual) { - var expectedArgs = Array.prototype.slice.call(arguments, 1); + compare: generateCompare(false), + negativeCompare: generateCompare(true) + }; + + function generateCompare(isNot) { + return function(actual) { if (!jasmine.isSpy(actual)) { throw new Error('Expected a spy, but got ' + jasmine.pp(actual) + '.'); } + + var expectedArgs = Array.prototype.slice.call(arguments, 1); + var actualCount = actual.calls.count(); + var actualArgs = actualCount && actual.calls.argsFor(0); + + var pass = (actualCount === 1) && util.equals(actualArgs, expectedArgs); + if (isNot) pass = !pass; + var message = function() { - if (actual.calls.count() != 1) { - if (actual.calls.count() === 0) { - return [ - 'Expected spy ' + actual.identity() + ' to have been called once with ' + - jasmine.pp(expectedArgs) + ' but it was never called.', - 'Expected spy ' + actual.identity() + ' not to have been called with ' + - jasmine.pp(expectedArgs) + ' but it was.' - ]; - } + var msg = 'Expected spy ' + actual.and.identity() + (isNot ? ' not ' : ' ') + + 'to have been called once with ' + jasmine.pp(expectedArgs) + ', but '; - return [ - 'Expected spy ' + actual.identity() + ' to have been called once with ' + - jasmine.pp(expectedArgs) + ' but it was called ' + actual.calls.count() + ' times.', - 'Expected spy ' + actual.identity() + ' not to have been called once with ' + - jasmine.pp(expectedArgs) + ' but it was.' - ]; + if (isNot) { + msg += 'it was.'; } else { - return [ - 'Expected spy ' + actual.identity() + ' to have been called once with ' + - jasmine.pp(expectedArgs) + ' but was called with ' + jasmine.pp(actual.calls.argsFor(0)), - 'Expected spy ' + actual.identity() + ' not to have been called once with ' + - jasmine.pp(expectedArgs) + ' but was called with ' + jasmine.pp(actual.calls.argsFor(0)) - ]; + switch (actualCount) { + case 0: + msg += 'it was never called.'; + break; + case 1: + msg += 'it was called with ' + jasmine.pp(actualArgs) + '.'; + break; + default: + msg += 'it was called ' + actualCount + ' times.'; + break; + } } + + return msg; }; + return { - pass: actual.calls.count() === 1 && util.equals(actual.calls.argsFor(0), expectedArgs), + pass: pass, message: message }; - } - }; + }; + } }, toBeOneOf: function() { diff --git a/test/jqLiteSpec.js b/test/jqLiteSpec.js index d67218ae8d95..e0502073d96d 100644 --- a/test/jqLiteSpec.js +++ b/test/jqLiteSpec.js @@ -972,7 +972,7 @@ describe('jqLite', function() { describe('text', function() { - it('should return null on empty', function() { + it('should return `""` on empty', function() { expect(jqLite().length).toEqual(0); expect(jqLite().text()).toEqual(''); }); @@ -1040,7 +1040,7 @@ describe('jqLite', function() { describe('html', function() { - it('should return null on empty', function() { + it('should return `undefined` on empty', function() { expect(jqLite().length).toEqual(0); expect(jqLite().html()).toEqual(undefined); }); diff --git a/test/modules/no_bootstrap.js b/test/modules/no_bootstrap.js index 64a7ed0e26ed..8248e367eb70 100644 --- a/test/modules/no_bootstrap.js +++ b/test/modules/no_bootstrap.js @@ -1,3 +1,3 @@ -// When runnint the modules test, then the page should not be bootstrapped. +// When running the modules test, then the page should not be bootstrapped. window.name = "NG_DEFER_BOOTSTRAP!"; diff --git a/test/ng/anchorScrollSpec.js b/test/ng/anchorScrollSpec.js index cbe2abdfc221..1a5832c93fd7 100644 --- a/test/ng/anchorScrollSpec.js +++ b/test/ng/anchorScrollSpec.js @@ -88,6 +88,9 @@ describe('$anchorScroll', function() { return function($window) { forEach(elmSpy, function(spy, id) { var count = map[id] || 0; + // TODO(gkalpak): `toHaveBeenCalledTimes()` works correctly with 0 since + // https://github.com/jasmine/jasmine/commit/342f0eb9a38194ecb8559e7df872c72afc0fe52e + // Fix when we upgrade to a version that contains the fix. if (count > 0) { expect(spy).toHaveBeenCalledTimes(count); } else { @@ -386,6 +389,9 @@ describe('$anchorScroll', function() { return function($rootScope, $window) { inject(expectScrollingTo(identifierCountMap)); + // TODO(gkalpak): `toHaveBeenCalledTimes()` works correctly with 0 since + // https://github.com/jasmine/jasmine/commit/342f0eb9a38194ecb8559e7df872c72afc0fe52e + // Fix when we upgrade to a version that contains the fix. if (list.length > 0) { expect($window.scrollBy).toHaveBeenCalledTimes(list.length); } else { pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy